- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2018 04:41 AM
Hi All,
I'm tried to copy the GlideRecord objects to an Array, so i can iterate through the array in HTML(view).
sample code -
var getHelpSupp = [];
var grSupp = new GlideRecord('u_get_help_support');
grSupp.addQuery('u_test_territory', lnk);
grSupp.orderBy('u_display_order');
grSupp.query();
while(grSupp.next()) {
//var test1 = grSupp;
getHelpSupp.push(grSupp);
}
// testing the data in array
for(var j=0; j<getHelpSupp.length; j++) {
var test = getHelpSupp[j];
console.log(test.u_support_label.getDisplayValue());
}
The query working fine, It fetching the 4 records from the table, the array size also a 4. but the issue all 4 records in the array is same, all are pointing to last record iterating in while loop GlideRecord.
It's some issue in copying the object in while it seems.
Anyone has faced same issue and has the solution pls.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2018 05:04 AM
Hi Chethan,
Following script you can try for example for pushing objects
var arr = [];
var gr = new GlideRecord('incident');
gr.setLimit(5);
gr.query();
while(gr.next()){
var obj = {};
obj.number = gr.number.toString(),
obj.shortDescription = gr.short_description.toString();
arr.push(obj);
}
gs.print(JSON.stringify(arr));
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
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
‎07-26-2018 05:04 AM
Hi Chethan,
Following script you can try for example for pushing objects
var arr = [];
var gr = new GlideRecord('incident');
gr.setLimit(5);
gr.query();
while(gr.next()){
var obj = {};
obj.number = gr.number.toString(),
obj.shortDescription = gr.short_description.toString();
arr.push(obj);
}
gs.print(JSON.stringify(arr));
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
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
‎07-26-2018 06:00 AM
Hi Ankur,
Thanks for your answer, it's working now.
If u don't mind, can i know the what is issue. It didn't for me?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2018 06:18 AM
Hi Chethan,
The way it was pushed into the array seems to be something weird. Also you were pushing glide record object and not javascript object notation.
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
‎12-01-2022 08:41 AM
Hi
how could we retrieve it in the client side?
here we sent a string to client side, it is an array of objects.
how the element of each object is accessible in client script