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

Awesome, happy to help.

Hi Michael, if you get a chance could you please look at this latest post for me:

https://community.servicenow.com/community?id=community_question&sys_id=9c5295b4db23d7c0f7fca851ca961976

Thanks as always.

Hi Michael, I'm having some difficulty with approval records and wondered if you might have any ideas. After a rejection, when it resets we're finding existing approval records that were showing as 'No longer required' (as expected, as part of another user's rejection) are resetting to 'Requested' - as well as new approval records being added for those approvers. Not sure if it's to do with the 'Disassociate approval records' stage needing amending as we've customized the technical approvals stage? Many thanks.

New post here for this query:

https://community.servicenow.com/community?id=community_question&sys_id=994f1033db63d300fff8a345ca96198c

Thanks.