- 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:54 AM
Hi
as you can see on page https://developer.servicenow.com/dev.do#!/reference/api/quebec/server_legacy/c_GlideRecordAPI there is no official method .getElements() for class GlideRecord.
What did you expect to get?
Kind regards
Maik
If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2021 02:57 AM
You are using .next method, there is no need to use this Method.
next() method returns the next element and also moves to the next element.
Try below code into Background Script, you will get Output.
var inc = new GlideRecord('incident');
inc.addActiveQuery();
inc.query();
gs.info(inc.getRowCount());
Please mark my answer as correct and close the thread so that others can also benefit.
Regards
Prasad Dhumal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2021 02:58 AM
Here my question is, while printing length of array, I am not getting the length.
Is there any error in my code... please explain my code only.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2021 03:02 AM
Did you get a chance to check my comments above
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);
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 03:05 AM
Actually getElements() methods returns array of objects, then why we agiain convert this to array?