Workflow Approval User Via Script

stevejarman
Giga Guru

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

}

16 REPLIES 16

samiul1
Tera Expert

Could you test your script in Background-Scripts and see if it's generating any result?


Also, can you test this:



  1. var answer = [];
  2. var rs = new GlideRecord("u_provisioning_approvers");  
  3. rs.addQuery("u_company", current.opened_by.company);  
  4. rs.query();  
  5.  
  6. while (rs.next()) {  
  7.       answer.push(rs.getValue('u_capacity_managers'));  
  8. }  

I was trying to avoid that as my u_capacity_managers field already has the ability to either be a single sys_id or a comma separated list of sys_ids if there's more than one approver. I guess I could split that into an array, but that seems silly when I already have it in one of the formats expected. I'll try it though and see what happens.


Did you manage to get any results using that method?