Various approvers - advanced approval script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2018 10:23 AM
Hi there!
I am trying to write a script on an Approver activity in a workflow. On the catalog item, a user will select a group on the variable GroupName. If the group has a manager, I want the group manager to be the approver. If there is no group manager, I want the Business Service Owner to be the approver. If the group does not have a manager or a Business Service Owner, I have 3 specific people I want to be the approvers but only one needs to approve. Here is what I have been trying and it does work when the group has a manager but after that it is not working
var answer = [];
if (current.variables.GroupName.manager != '')
{answer.push (current.variables.GroupName.manager.sys_id.toString());}
else if (current.variables.GroupName.business_service_ownerDONOTUSE != '')
{answer.push(current.variables.GroupName.business_service_ownerDONOTUSE.sys_id.toString());}
else
{answer.push('13ece655db949340b3613caf9d9619f6');
answer.push('5bec2a55db949340b3613caf9d961948');
answer.push('5fec2a55db949340b3613caf9d961919');}
On the last else statement, those are the sys ids of the three people to be the approvers if no manager and no business service owner
- Labels:
-
Best Practices
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2018 10:27 AM
You need to switch workflow activity to generate approvals based on variables value selected
Please follow below for more details
https://docs.servicenow.com/bundle/jakarta-servicenow-platform/page/administer/workflow-activities/reference/r_Switch.html
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2018 10:39 AM
I don't think that will work because there are hundreds of groups, thank you though.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2018 10:44 AM
Please check below which has solution for implementing hierarchical approvals
https://community.servicenow.com/community?id=community_question&sys_id=05990ba5db5cdbc01dcaf3231f961987
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2018 10:46 AM
Please try below script. Also make sure you are using Approval-User activity. Also confirm, you are running it on Requested Item table and not on Request table
var answer = [];
if (current.variables.GroupName.manager != '')
{
answer.push(current.variables.GroupName.manager.toString());
}
else if (current.variables.GroupName.business_service_ownerDONOTUSE != '')
{
answer.push(current.variables.GroupName.business_service_ownerDONOTUSE.toString());
}
else
{
answer.push('13ece655db949340b3613caf9d9619f6');
answer.push('5bec2a55db949340b3613caf9d961948');
answer.push('5fec2a55db949340b3613caf9d961919');
}
Please mark this response as correct or helpful if it assisted you with your question.