Indexing in Glide Record

gowthams1024
Kilo Contributor

Hi All,

I was working on a script, and I am facing difficulties in looping through the result set. PFB code

var stageUsers = GlideRecord('sys_user');

stageUsers.addQuery('u_first_name','CONTAINS','test');

stageUsers.query();

var userArray = [];

while(stageUsers.next()) {

gs.log(stageUsers.u_first_name);

userArray.push(stageUsers.u_first_name);

}

Assuming 5 users match the criteria: TestUser1,TestUser2,TestUser3,TestUser4,TestUser5

gs.log is printing these 5 users. However, userArray is having 5 entries of TestUser1.

Any idea on how to index the results?

We can save the result to a variable, split it and assign it to an array. But I need to know if we have any method in JavaScript \ ServiceNow OOTB.

6 REPLIES 6

bernyalvarado
Mega Sage

I hope this helps


bernyalvarado
Mega Sage

Hi gowthams1024, I just noticed that this thread is still not marked as answered. Would you mind selecting one of the responses as correct so that we can set it to answered?



Thanks,


Berny