Loop Through Approvals and Return Values

jmiskey
Kilo Sage

I have a list of Approvals for a particular RITM that I am trying to loop through and return a value from a Custom field for all the Rejected Approvals.  However, I cannot get it to return all the values, it only returns one.

Here is what the Approvals look like:

jmiskey_0-1672943845652.png

As you can see, there are two rejected approvals.  I am trying to run a Script in my workflow to return the "Active Directory Code" values for the two Rejected records. 

Here is the code I have in my Run Script action:

 

gs.log('Selections: ' + workflow.scratchpad.sp_totalSelections,'Joe1');

 

//query for Rejected Approvals

var gr = new GlideRecord('sysapproval_approver');

gr.addQuery('sysapproval',current.sys_id); //only run on current RITM

gr.addQuery('state','Rejected'); //only look at approved records

gr.query();

 

gs.log('Count: ' + gr.getRowCount(),'Joe2');

var list =[];

 

while(gr.next()){

                list.push( gr.u_active_directory_code);

}

gs.log('Sys IDs: ' + list.toString(),'Joe3');

 

And here is what it returns:

jmiskey_1-1672943953507.png

As you can see, it returns the same value twice, instead of each individual value.

 

Originally, I tried putting my log statement right within the "While" step, but then it just returned a single value, instead of two (even though it is counting 2).

 

Can anyone see what I am doing wrong? Am I iterating through the Glide Record incorrectly?

 

Thanks

1 ACCEPTED SOLUTION

Nia McCash
Mega Sage
Mega Sage

Instead of

 

list.push( gr.u_active_directory_code);

 

 

use

 

list.push( gr.getValue('u_active_directory_code'));

 

 

See https://snprotips.com/blog/2017/4/9/always-use-getters-and-setters for technical explanation

View solution in original post

2 REPLIES 2

Nia McCash
Mega Sage
Mega Sage

Instead of

 

list.push( gr.u_active_directory_code);

 

 

use

 

list.push( gr.getValue('u_active_directory_code'));

 

 

See https://snprotips.com/blog/2017/4/9/always-use-getters-and-setters for technical explanation

jmiskey
Kilo Sage

Thank you!