- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2021 01:31 AM
while executing the below, I am not getting the length of list.
var inc = new GlideRecord('incident');
inc.addActiveQuery();
inc.query();
inc.next();
var list = inc.getElements()
gs.print(list.length);
showing output: undefined
why? please explain..
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2021 03:12 AM
Seems the docs has incorrect information.
I tried the script from docs to get the length but it failed
We need to convert that to Array and then get the length
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
‎03-30-2021 01:39 AM
try now
var inc = new GlideRecord('incident');
inc.addActiveQuery();
inc.query();
gs.print(inc.getRowCount());

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2021 01:41 AM
To check the row count you can use getRowCount().
Doc reference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2021 01:50 AM
Hi,
getElements() would give you java object so convert that to Array and then use length
Script: This will give the length
var inc = new GlideRecord('incident');
inc.addActiveQuery();
inc.query();
inc.next();
var list = new global.ArrayUtil().convertArray(inc.getElements());
gs.info(list.length);
Output:
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
‎03-30-2021 01:51 AM
Note: getElements() does not give list of rows details. It will return an array of GlideElement objects. Each object describes a field in the current GlideRecord.
eg: