Impact of deactivating user group on Workflows that reference it
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
I'm new to ServiceNow administration, so apologies if this is a silly question.
I am trying to figure out the impact of deleting or deactivating (unchecking the "Active" box) on a user group for Workflows that reference the group.
My specific scenario is this:
My organization has a bunch of different markets, each with an "approval group" for Service Catalog requests. For Market 1 there is a group called "MKT01 - Approval Group", for Market 2 there is a group called "MKT02 - Approval Group", etc.
The only users who are actually members of the approval groups are the managers who can approve requests for their respective markets. However, we have an "Approval Group" reference field on the user table that contains a reference to the appropriate approval group for each user depending on what market they are in.
We have workflows for Catalog Item approvals . The logic on these is that there is a standard two-tier approval process which goes to a group called "Approval - lvl 1" first and then to a group called "Approval - lvl 2" for final approval. But certain markets have "special" approval rules and want to add an additional approval step before these two, if the requested item has a cost greater than $0 (or $5000 depending on the market).
To support this, the approval workflows contain an approval step before these standard two stages that uses a script to determine the Approvers to send the request to. The script retrieves the value of the "Approval Group" reference field for the user making the request (as long as the cost is greater than $0) and then checks if that value matches any of the approval groups for the markets that want the additional approval. If it does, it retrieves the members of the approval group (which is the approving manager) and sends the approval to them (for a couple of markets even if the group matches it only proceeds to retrieve the approving manager if the cost is greater than $5000). If the group does not match, then it automatically approves this stage and moves on to the subsequent approvals.
Below is the code used in the "Approvers" section of the "Approval - User" tile shown above labelled "Group Check":
var answer = [];
function determinePrice() {
var price = current.price;
if (price > 0) {
return true;
} else {
return "no";
}
}
function determineUserGroup() {
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", "=", user);
gr.query();
if (gr.next()) {
gs.log("sysid = " + gr.sys_id)
var approvalGroup = gr.u_approval_group;
gs.log(gr.name + " has the approval group of " + approvalGroup)
return approvalGroup
} else {
gs.addErrorMessage("Unable to determine user's approval group. Is your session still active?");
return false;
}
}
function doLogic(approvalGroup) {
if (approvalGroup == "<redacted1>") {
if (current.price > 5000) {
gs.log("mkt01")
return determineApprovingManager("<redacted1>")
}
}
if (approvalGroup == "<redacted2>") {
if (current.price > 5000) {
gs.log("mkt02")
return determineApprovingManager("<redacted2>")
}
}
if (approvalGroup == "<redacted3>") {
gs.log("mkt03");
return determineApprovingManager("<redacted3>")
}
if (approvalGroup == "<redacted4>") {
gs.log("mkt04");
return determineApprovingManager("<redacted4>")
}
if (approvalGroup == "<redacted5>") {
gs.log("mkt05");
return determineApprovingManager("<redacted5>")
}
if (approvalGroup == "<redacted6>") {
gs.log("mkt06");
return determineApprovingManager("<redacted6>")
}
if (approvalGroup == "<redacted7>") {
gs.log("mkt07");
return determineApprovingManager("<redacted7>")
}
if (approvalGroup == "<redacted8>") {
gs.log("mkt08");
return determineApprovingManager("<redacted8>")
}
if (approvalGroup == "<redacted9>") {
gs.log("mkt09");
return determineApprovingManager("<redacted9>")
}
if (approvalGroup == "<redacted10>") {
gs.log("mkt10");
return determineApprovingManager("<redacted10>")
}
}
function determineApprovingManager(approvalGroup) {
var gr = new GlideRecord("sys_user_grmember");
gr.addEncodedQuery("group=" + approvalGroup)
gr.query();
var user = [];
while (gr.next()) {
gs.log(gr.user)
user += gr.user + ",";
answer.push(user)
}
gs.eventQueue("generalRequestEmailtoEmail", "sc_req_item", approvalGroup);
return answer
}
if (determinePrice()) {
var result = determineUserGroup()
gs.log("answer = " + doLogic(result))
}
One of the markets has decided they do not need this special approval. I was asked to just "turn off" that group. My question is, with the sys_id's of the groups for these markets hard coded as shown above (these are the redacted values), what will be the impact if one of the groups is deactivated? Would this cause the flow to error or would it just act like the group did not match and proceed as normal? What if the group was deleted?
I'm mainly trying to determine if I need to edit the scripts in these flows to remove references to the group that no longer needs the special approval or if the group could just be deactivated or deleted.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago
This is a lot to unpack, firstly I think this process needs a re-work and built in flow designer.
Secondly, do you not have a non-prod environment where you can simply test deactivating the group and raising the request? From my understanding of this code though, you're assigning the approval to a specific member of that group, not the group itself so it would still generate the approval to the person as you do not have an active true query anywhere in your code.
So to remove the group and also remove it from this process, you'll need to amend your code.
