The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to assign users in Approval-User activity through script

jpavanaryan
Tera Expert

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');

}

}

9 REPLIES 9

Bryan Tay3
Mega Guru

hi jpavanaryan,



have u tick the "Advanced" check box?


this works for my instance (helsinki).



find_real_file.png


hi bryan,

i have tried the same but it is not working can u suggest me what are tips need to be foillowed

hi Deepthi, 

you can check out my other reply in this thread.

hopefully it helps.

cheers. 🙂

jpavanaryan
Tera Expert

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.