- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2020 05:59 AM
Hi ,
I need to separate each of these below arrays into 8 separate arrays so that I can pass these to a method. Now the length shows as the length of total string and not 8.
contentMap received :[
{"column":"u_kb_index","content":"SCOM_CUSTOM_Service-Health_BY0VBV","table":"u_kb_template_gems","number":"KB0022149"},
{"column":"u_kb_source","content":"SCOM","table":"u_kb_template_gems","number":"KB0022149"},
{"column":"u_kb_monitor_description","content":"<p>QA Airwatch API Service is Down<br /><br /> <span style=\"font-family: Calibri;\">Summary: </span><br /><span style=\"font-family: Calibri;\">The Airwatch Application Service or IIS or World Wide Web Publishing Service is not running</span></p>","table":"u_kb_template_gems","number":"KB0022149"}]
Please help.
Thanks in Advance,
Chinmayee Mishra
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2020 06:21 AM
So that seems to be alright now. You have 8 entries. So length is returning 8?
Then you can loop through that like:
for(var i=0;i<contentArr.length;i++){
gs.info(JSON.stringify(contentArr[i]));
//do something with the object
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2020 06:03 AM
Hi,
you can iterate over the array and send each json object as string to another function
sample below
var contentArr = []; // this is your complete array of json objects
for(var i=0;i<contentArr.length;i++){
var obj = new ScriptInclude();
obj.yourFunction(JSON.stringify(contentArr[i])); // pass the json string for the object to another function
}
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
10-25-2020 06:20 AM
contentArr.length is 5589
It should loop for 8 times only
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2020 06:22 AM
Hi,
array should give 8 as that array contains 8 json objects
can you try printing this
gs.info('element 1' + JSON.stringify(contentArr[0]));
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
10-25-2020 06:26 AM
it should work
I just tried this in scripts background
var arr = [
{"column":"u_kb_index","content":"SCOM_CUSTOM_Service-Health_BY0VBV","table":"u_kb_template_gems","number":"KB0022149"},
{"column":"u_kb_source","content":"SCOM","table":"u_kb_template_gems","number":"KB0022149"},
{"column":"u_kb_monitor_description","content":"<p>QA Airwatch API Service is Down<br /><br /> <span style=\"font-family: Calibri;\">Summary: </span><br /><span style=\"font-family: Calibri;\">The Airwatch Application Service or IIS or World Wide Web Publishing Service is not running</span></p>","table":"u_kb_template_gems","number":"KB0022149"}];
for(var key in arr){
gs.info('element' + JSON.stringify(arr[key]));
}
Output:
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader