- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-18-2018 11:43 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-20-2018 06:29 AM
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-18-2018 11:49 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-18-2018 11:54 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-18-2018 12:19 PM
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-18-2018 02:51 PM
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.