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

hi jpavanaryan,



Perhaps u can try adding following between line 49 and 50 in your code to check?


gs.log('Response = '+answer+','+answer.length);



In the mean time, in my own script, i push "User ID" instead of sys_id.



answer.push('tayb');



e.g.


        find_real_file.png



Hope this helps.


Thanks. I was trying with Sys Id's


hi jpavanaryan,



does it works when u push it with user id?



don't forget to mark my response as the answer for other users reference.



cheers...:)


Looks like I opened this question as Discussion. I can not mark this answer now. Sorry


no problem.