Create dynamic approval group based upon user table field?

Isaac10
Giga Expert

In our Change workflow we have an initial approval by the assignment group. It's an OOB step called Technical Approvals. Our managers are not part of their groups. They have requested:

  1. That they (the managers) be part of the group
  2. That they have the ability to choose who on their teams can approve (they may not want the entire team to be an approver)

To facilitate this we added a true/false button to the user record called: u_change_assessment_approver

How can I tell the approval to look at the assignment group and send the approval request to only those users of that group who have u_change_assessment_approver marked true?

Additionally how can I have it also send that approval to the manager of that group?

Thanks all!

1 ACCEPTED SOLUTION

dooo sorry much easier.. this is in a change workflow right?? if so do this instead in a user approval script



  1. var answer = [];  
  2. var counter = 0;
  3. var failsafe_sid = 'sid of change manager or whoever will approve if there are no active approvers';
  4. answer.push(current.assignment_group.manager.toString());   //this pushes the manager of the group to the approvers
  5. var users = new GlideRecord('sys_user_grmember');
  6. users.addQuery('group',current.assignment_group);   //find members of the group
  7. users.addQuery('user.u_change_assessment_approver',true);   //check to see if they are a change approver
  8. users.query();
  9. while(users.next()){
  10.       answer.push(users.user.toString());
  11.       if(users.user.active){
  12.                   counter++;
  13.       }
  14. }
  15. if(counter == 0){answer.push(failsafe_sid)}

View solution in original post

11 REPLIES 11

Chuck Tomasi
Tera Patron

Build your approval via the advanced script in the approval. Use the GlideRecord query on the table sys_user_grmember to get the members of the team (that table has a group field and user field to make it easy to query.) Once you have retrieved a user, save it in the answer array only if it has that new field set to true.



Approval - User


GlideRecord


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Issac,



Here is the sample script as per your req.


Script :


var answer = [];


var grusr = new GlideRecord('sys_user_grmember');


grusr.addQuery('group.name','PASS GROUP NAME HERE');


grusr.addQuery('user.u_change_assessment_approver','true');


grusr.query();


while(grusr.next())


{


answer.push(grusr.getValue('user'));  


}


Just a tweak grusr.user will get you the sys_id of the user. No need to dot walk to the sys_id field.


randrews
Tera Guru

ok i wouldn't do this as a group approval.. but as a user approval....



now i would build a script to push the approvals based on the group member table... and the group table.. first get the group record and add the group manager...



then thumb through the group member table for all of the members of the group get the user record and if they have the new field as true you add them



the one thing you will want to do is also verify the members are active.. and count the active people you add.. the way approvals work if there are no active approvers it is auto approved.. you will probably want a fail safe approver in case you end up with no active approvers.



when you use a group approval it is looking for GROUPS to add.. and you can't sort the people out.. when you use a user approval it is looking for a list of people to add.. so anytime you want only some members of a group you need to use a user approval not a group approval... let me know if you need more info on the tables to query.