Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to retrieve the list of records through gliderecord?

Not applicable

Requirement: I need to retrieve the list of records through Gliderecord. I used below code but it is only retrieving the first record in the list.

1 ACCEPTED SOLUTION

Mohith Devatte
Tera Sage
Tera Sage

Hello 

please change the if to while

also if you want all names like this

var arr=[];

var obj2 = new GlideRecord('cmdb_rel_ci');

obj2.addEncodedQuery('yourencodedquery');

obj.query();

while(obj.next())

{

arr.push(obj2.child.getDisplayValue());

}

gs.info('My object names'+arr.toString)

PLEASE MARK MY ANSWER CORRECT IF IT HELPS YOU

View solution in original post

10 REPLIES 10

Mohith Devatte
Tera Sage
Tera Sage

Hello 

please change the if to while

also if you want all names like this

var arr=[];

var obj2 = new GlideRecord('cmdb_rel_ci');

obj2.addEncodedQuery('yourencodedquery');

obj.query();

while(obj.next())

{

arr.push(obj2.child.getDisplayValue());

}

gs.info('My object names'+arr.toString)

PLEASE MARK MY ANSWER CORRECT IF IT HELPS YOU

Hi Mohit,

I tried this way, still getting only first record in a list.

var obj2 = new GlideRecord('cmdb_rel_ci');

obj2.addEncodedQuery('yourencodedquery');

obj2.query();

while(obj.next())

{

arr.push(obj2.child.name.toString());

}

gs.info('My object names'+arr.toString())

try this

still getting one record.