How to assign users in Approval-User activity through script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2017 05:24 PM
In my workflow, I need to assign to approvers based on user region. I tried implementing this through a script in 'Additional approvers script'. But the workflow Approval-User activity being skipped when I try to assign approvers to answer array as shown below.
// Set the variable 'answer' to a comma-separated list of user ids and/or group ids or an array of user/group ids to add as approvers.
//
// For example:
//current.variables.assigned_to='4562471f13fccfc079c0b4a76144b0d0,d4193a21130d430079c0b4a76144b042';
//current.variables.assigned_to='4562471f13fccfc079c0b4a76144b0d0';
answer = [];
var gr=new GlideRecord('sys_user');
gr.addQuery('sys_id',workflow.scratchpad.user_sysid);
gr.query();
if(gr.next())
{
if(gr.department.name == 'Residential US Floors')
{
//Assign to 'Sam D Ruble'.
//Sam Ruble sys_id :5bac349edb8b7a04c1d57c1ebf96191e
answer.push('5bac349edb8b7a04c1d57c1ebf96191e');
}
if(gr.department.name == 'Residential Hard Surface')
{
//Assign to 'Scott Sandlin'.
//Scott Sandlin sys_id :ea494c7a0a0a3c1f00a5c2702b3c9a2a
answer.push('ea494c7a0a0a3c1f00a5c2702b3c9a2a');
}
if(gr.department.name == 'Residential Speciality Markets')
{
//Assign to 'Craig Callahan'.
//Craig Callahan sys_id :5bac349edb8b7a04c1d57c1ebf96191e
//answer.push('5bac349edb8b7a04c1d57c1ebf96191e');
//Setup Craig Callahan User account
}
if(gr.department.name == 'Commercial')
{
//Assign to 'Doug Enck'.
//Doug sys_id :196719c60a0a3c4901dec48da956e4b0
answer.push('196719c60a0a3c4901dec48da956e4b0');
}
}
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2017 11:01 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-25-2018 04:51 AM
hi bryan,
i have tried the same but it is not working can u suggest me what are tips need to be foillowed

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-01-2019 06:25 PM
hi Deepthi,
you can check out my other reply in this thread.
hopefully it helps.
cheers. 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-10-2017 03:11 PM
I checked 'Advanced' box. ServiceNow skips Approval-User activity when users field is empty or not assigned a value irrespective of the additional approver's script. I was able to assign the request to one user by placing run script activity and with script current.assigned_to='82182591db0d8740478f5bc0cf961940'; before 'Approval-User' activity. But it does not accept multiple users, when assigned multiple users it skips activity.