Are workflow approvals based on parent and child groups (and more!) possible!?

jas101
Tera Expert

Hi guys, would really appreciate it if anyone can help with this. We are hoping to update our change request workflows so that when 'Technical approvers' are added everyone in the Service.Approval group is added and all are required. Easy right!

However we'd also like it so that members of any child/sub groups of this approval group are added also - however only one approval from each of these child groups would be required.

Finally, if a particular change field, 'Business impact' has a value we would also like to include other  specific customer service related approval groups. The approval group would be dependent on the 'Impacted region(s)' (a list field) of the change so for example approval group 'CS-USA', if 'USA' is selected or e.g. 'CS-USA' AND 'CS-Canada' if  'Impacted region(s)' values are USA and Canada (from these groups only one approval is required).

So big question, is it possible to somehow tie this up in one approval group activity and if so how?! Thank-you guys.

1 ACCEPTED SOLUTION

Thanks for confirming.  The following script should work.  Click the advanced checkbox in the group approval activity and paste this in.  It first sets up the answer array and then validates there is a business service set on the change and that the business service also has an approval group defined before calling the function to gather the child groups.

Please mark this post or any as helpful or the correct answer to your question so others viewing can benefit.

 

var answer = [];

// Validate there is a business service and approval group
if (current.business_service && current.business_service.change_control) {
	recursChildGroups(current.business_service.change_control);
}

function recursChildGroups(group){
   //Make sure that we have a valid group ID
   if(group){
      if(group.toString().length == 0){
         return null;
      }
      //Query for the active child groups of this group
      var rec = new GlideRecord('sys_user_group');
      rec.addQuery('parent', group);
      rec.addQuery('active', true);
      rec.query();
         while(rec.next()){
            //If the group has already been added then do not add again
            if(answer.toString().indexOf(rec.sys_id.toString()) > -1){
               continue;
            }
            //Add the group to the final array
            answer.push(rec.sys_id.toString());
            //Find the child groups of this group
            recursChildGroups(rec.sys_id.toString());
         }
   }
   return null;
}

View solution in original post

12 REPLIES 12

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

You will need an approval coordinator activity to bring all of these together if they all need to happen in parallel/at same time.  The coordinator will allow you to have multiple iterations of groups and users with different requirements.  Then you will need to click advanced and create a script to gather the groups required for approval.  Definitely possible though.

jas101
Tera Expert

Ha thanks Michael, I've actually just been creating a new 'Approval co-ordinator' activity in the workflow as I got your notification. This is going to make the Service.Approval group and the CS approval group(s) aspect easy from what I have seen so far, however I think I'm going to need some help if possible please with adding the child groups of the Service.Approval group - any idea on this? Thank-you.

Fortunately SNGuru has documented on how to recursively search through groups in this article:

https://www.servicenowguru.com/scripting/script-includes-scripting/advanced-getmygroups-function/

 

So taking this approach, you can use code similar to the following.  You just need to pass in the group SysID into the function:

var answer = [];
recursChildGroups(group);

function recursChildGroups(group){
   //Make sure that we have a valid group ID
   if(group){
      if(group.toString().length == 0){
         return null;
      }
      //Query for the active child groups of this group
      var rec = new GlideRecord('sys_user_group');
      rec.addQuery('parent', group);
      rec.addQuery('active', true);
      rec.query();
         while(rec.next()){
            //If the group has already been added then do not add again
            if(answer.toString().indexOf(rec.sys_id.toString()) > -1){
               continue;
            }
            //Add the group to the final array
            answer.push(rec.sys_id.toString());
            //Find the child groups of this group
            recursChildGroups(rec.sys_id.toString());
         }
   }
   return null;
}

Thanks for this Michael but to confirm sorry, would this script go in the 'Additional groups script' box which shows when 'Advanced' is checked on an 'Approval - Group' workflow activity?

And if this is correct how do I need to modify it so it is looking for any members (potential approvers) of child groups of whatever Service.Approval group is selected (i.e. the group sys ID can't be hard-coded although this is probably not what you meant)? Or do I specify Service.Approval group using the 'Groups' field as well as using the script box? Thank-you.