- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2023 10:35 AM - edited 01-05-2023 10:41 AM
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:
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:
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2023 11:29 AM - edited 01-05-2023 11:33 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2023 11:29 AM - edited 01-05-2023 11:33 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2023 05:28 AM
Thank you!