- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 10:16 AM
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.

Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 10:20 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 10:38 AM
Hmm strange .check the row count in the table please?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 10:51 AM
checked, there are 7 records in the table by applying filter which i have used in encodedquery.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 10:44 PM
There was silly mistake in your code, i correct it now it's working. Thank you so much.
gs.info('My object names'+arr.toString());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 10:37 AM
Hi,
are you sure there are more than 1 records satisfying your query?
try adding this to get row count gs.info(obj2.getRowCount());
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 10:42 AM
Hi,
Not sure if this is the complete code.
1. I see sysid2 is not defined here.
2. Declare names as array outside while loop and push the values into the array.
3. Your return shoudl be outside of while loop (change if to while).
Also, as others suggested do chck if you actually have more rows using getRowCount().
Mark the comment as a correct answer and also helpful if this has helped to solve the problem.
