Group and Manager approval in workflow

M_iA
Kilo Sage

I am building a workflow for SN group access requests.

On the sys_user_group table we have the group manager field and I have just created an access approval group field (u_access_approval_group). So in this set up, either the manager or group must be completed. In some cases, both will be complete.

Now on the workflow, I already have an approval script set up for the manager:

 

var gr = new GlideRecord("sys_user_group");
gr.addQuery("sys_id", current.variables.access_group_required);
 
gr.query();
var answer = [];
while (gr.next()) {
    if (gr.manager != ''){
        answer.push(gr.manager);
    }
}

 

So, in the new process, I would like the approvals to go to all of the members in the group and groups manager. Taking into account that one of the fields on the group maybe empty.

 

How would I incorporate this into the script?

Many thanks

1 ACCEPTED SOLUTION

Laszlo Balla
ServiceNow Employee
ServiceNow Employee

Yes, need to actually look-up the approval group and not the current group. I have updated the code (but still couldn't test it, so maybe add some debugging to see if if works?)

 

var gr = new GlideRecord("sys_user_group");
gr.addQuery("sys_id", current.variables.access_group_required);
 
gr.query();
var answer = [];
while (gr.next()) {
    if (gr.manager != ''){
        answer.push(gr.manager);
    }
  var approvalGroup = gr.getValue('u_access_approval_group');
  if(approvalGroup) {
    addGroupApprovers(approvalGroup);
  }
}

function addGroupApprovers(group) {
  if(!group) {
    return;
  } else {
    var grMember = new GlideRecord("sys_user_grmember");
    grMember.addQuery("group",group);
    grMember.query();
    while(grMember.next()) {
      answer.push(grMember.user);
    }
  }  
}

 

View solution in original post

5 REPLIES 5

Laszlo Balla
ServiceNow Employee
ServiceNow Employee

Great job! 👏🏻