- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2022 05:53 AM
Hello Team,
Is there any way I can push Glide object as a value in an array-
Eg.
var users = [];
var a = new GlideRecord('sys_user');
a.addQuery('active',true);
a.setLimit(5);
a.query();
while(a.next()){
//*******************HERE I HAVE DOUBT
users.push(a);
//*******************
}
for(var index in users){
var inc = new GlideRecord('incident');
inc.initialize();
inc.caller_id = users.data[index].sys_id;
if(inc.insert()){
gs.info('INCIDENT is created '+inc.number);
}
}
For now there is only 1 value storing in an array, as it is object and not string I can't even use toString(), is there any way I can store all object records from loop in an array
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2022 06:27 AM
Here's an example of how you can push an entire GlideRecord object into an array:
var users = [];
var obj = {};
var a = new GlideRecord('sys_user');
a.addQuery('active',true);
a.setLimit(5);
a.query();
while (a.next()) {
for (var key in a) {
obj[key] = a[key].toString();
}
users.push(obj);
}
gs.print(JSON.stringify(users));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2022 06:43 AM
Thanks Brad,
This seems like something which I can use in my script.
I'll try it out .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 02:33 AM
trying these steps and still facing same issue. tried this very same code in scripts- background, even this code is not working as expected in scripts - background for me. Pls help, is there any alternate way to push glide objects into array.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Wednesday
If anyone else is running into this, I had to move the declaration of the 'obj' variable inside of the while loop.