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

Hi Michael, to confirm my earlier reply I have now used an Approval coordinator activity and within this I have:

-5 x Approval group activities based on condition 'Region(s)' which adds the relevant region's Customer Service approval group (1 approver from each group required) - working OK

-1 x Approval group activity based on Change.Service.Approval group (all approvers in this group required) - working OK

-1 x Approval group activity which is to be based on Change.Service.Approval group.Child group(s) - where 1 approver from the group(s) is/are required

This last approval activity is where I'm not entirely sure how best to utilise the script you kindly provided. Any further help with this is greatly appreciated. Thank-you.

Can you please provide the "dot-walked" field that has the approval group?  It will be something like current.service_offering.change_control. 

Hi, sure - the field we're using is the 'Approval group' on the Service record, that is selected by the change owner on the change form via a reference field called Service ('business_service'). So it's business_service.change_control 

Hope this helps. Thanks.

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;
}

This is just the ticket and appears to be working great, BIG thank-you Michael!