- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2020 05:13 AM
Hi,
Below is the script which i have written i am trying to get the legnth of objects element but i am not getting correct result
var arr = [];
var serverName = "c56c1c49db7657c4375d5458dc961965";
//var reqFor = current.variables.Requested_for;
var gr = new GlideRecord('cmdb_rel_ci');
gr.addQuery('child', serverName);
gr.addQuery('parent.sys_class_name', 'u_application');
gr.query();
while(gr.next()){
var obj = {};
obj.name = gr.parent.u_accountable_application_owner.getValue().toString() +',' + gr.parent.u_technical_owner.getValue().toString(); //Concatenating reference and list type fields in obj name
arr.push(obj);
}
gs.print(JSON.stringify(arr));
arr = JSON.stringify(arr);
var sp = arr.split(",");
gs.print(sp.length);
Result:
*** Script: [{"name":"557e1f107bb300002e3ddb30aa4d4dce,c77e93907bb300002e3ddb30aa4d4d0b"},{"name":"557e1f107bb300002e3ddb30aa4d4dce,efe87b277bd0d0002e3ddb30aa4d4d68,1f7e9fdc7b7300002e3ddb30aa4d4d3f"}]
*** Script: 5
I am expecting the length to get as 2 since i have two name objects within the array. Please help me how to acheive this
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2020 05:21 AM
Hi there,
Did you also try arr.length? Instead of sp.length? sp.length being 5 seems fair. Though you are already interested in arr I think.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2020 05:21 AM
Hi there,
Did you also try arr.length? Instead of sp.length? sp.length being 5 seems fair. Though you are already interested in arr I think.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field