Workflow script "answer.push" question

zzsrvnow
Giga Contributor

Hello All.

If "Request by" user is the member of the Approvers group (Assignment Group) we should exclude this user from the Approvers list. To exclude "Requested by" user from the Approvers list I'm using the code bellow. Debugging statement [workflow.info('APPROVER = ' + approvers.user.toString());] recording in the log all approvers correctly. In simple words the code is working.  However, retrieved approvers are not displayed  on the Approvers list on the form.

Please, any suggestions for me?   Thank you in advance for your help.

SCRIPT:

answer = [];
var approvers = new GlideRecord('sys_user_grmember');
approvers.addQuery('group', current.assignment_group);  
approvers.query();
while(approvers.next()) {  
   if(approvers.user.toString() != current.requested_by.toString()) {
    workflow.info('APPROVER = ' + approvers.user.toString());            
    answer.push(approvers.user.toString());

       }
}

Approvers are not displayed on the list:

find_real_file.png

 

Even the log says approvers are retrieved correctly:

find_real_file.png

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi,

 

I'm assuming that you are using "Approval group" activity and not "Approval User" activity in the workflow. If yes, then switch it to the "Approval user" activity and the script should work fine.

 

Thanks,

Pradeep Sharma

View solution in original post

5 REPLIES 5

erik_brostrom
Mega Guru

Try defining your answer at the end of your script, i.e.

var appAr = [];
var approvers = new GlideRecord('sys_user_grmember');
approvers.addQuery('group', current.assignment_group);   
approvers.query();
while(approvers.next()) {   
   if(approvers.user.toString() != current.requested_by.toString()) {
    workflow.info('APPROVER = ' + approvers.user.toString());             
    answer.push(approvers.user.toString());

       }
}

answer = appAr;

I tried as you suggested, Erik. It raised an error, - illegal access to getter method getMessage. Thank your willing to help and for your kindness.

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi,

 

I'm assuming that you are using "Approval group" activity and not "Approval User" activity in the workflow. If yes, then switch it to the "Approval user" activity and the script should work fine.

 

Thanks,

Pradeep Sharma

Super! You are absolutely right, Pradeep. We used "approval group" activity, when I replaced it with the "approval user" activity the code is working like a charm. 🙂 I'm not sure why, specially regarding to the description of the "approval group" it should create an approval record for  each member of the group. But the problem is solved. Thanks a million!