Workflow Approval User Via Script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2016 09:37 PM
I'm attempting to set up an approval using the "Advanced Additional Approvers Script". The script I'm using is shown below. u_capacity_managers is a User reference, and I can confirm that answer ends up being set to the sys_id of the correct user (I've printed it into a field to check via current.description = answer), BUT, the approval step just skips through as though no one is being set as the approver. Can anyone identify any problems with what I'm doing?
// 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:
// answer = [];
// answer.push('id1');
// answer.push('id2');
var rs = new GlideRecord("u_provisioning_approvers");
rs.addQuery("u_company", current.opened_by.company);
rs.query();
while (rs.next())
{
answer = String(rs.u_capacity_managers);
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2019 10:54 PM
This is working fine now
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2021 12:28 PM
I had a similar issue in Paris with both Approval User and Approval Group Activities in Workflow. If the User or Group was not selected from the static field values, then the Approval action completed as if Approved without sending any Approvals, even though there was a advanced script for additional approvers script or additional groups. The current Paris documentation for the Approval User Activity in the ServiceNow docs states:
"Users - The users for the approval. Use the tree icon to select user reference fields from the current record to create approvals, such as ${assigned_to}
. If no user is selected, the activity automatically sets the approval to Approved."
Setting the last line of code in the script (or in my try/catch block) to reference the answer variable solved the problem:
answer = xxxx;
or something like:
answer.push(SomeSysId);
This worked and the approvals were created for those returned from the script, even though no User or Group had been selected from the slushbucket.
This seemed similar to the requirement when putting javascript: in a Reference Qualifer - the last line (if you put it on multiple lines) should contain the result variable or value that is returned.