- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2017 06:40 AM
Hi All,
I just have a little question about populating glide_lists with arrays: I was using the below code to populate an array with the results of a glide record query and then was trying to populate a glide list field with the contents of that array.
var gr = new GlideRecord('sys_user_group');
gr.addEncodedQuery('u_opco.country=Uganda');
gr.query();
var arr = [];
while(gr.next()){
arr.push(gr.getValue('sys_id'));
}
for(var i = 0; i < arr.length; i++){
gs.log('this is the array: ' + arr[i]);
current.u_support_group += arr[i];
}
So in my logs i had the sys_id of each group logged on separate lines but in the list field it entered them all joined together as one giant sys_id. I thought arrays were a comma separated list so i'm a bit confused why this happened?
I played around with various things to split(',') the array but i ended up ditching the whole for(var i-0; i<arr.length; i++) bit and just put the below which works perfectly. I'd just like to know why my original method didn't work?
current.u_support_group = arr.join(',');
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2017 06:43 AM
The glide list field stores a comma separated list of sys_ids. Your first solution doesn't have any commas. It's just appending them all together.
current.u_support_group += arr[i];
Using join() does a much cleaner job of this.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2017 06:43 AM
The glide list field stores a comma separated list of sys_ids. Your first solution doesn't have any commas. It's just appending them all together.
current.u_support_group += arr[i];
Using join() does a much cleaner job of this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2017 06:49 AM
Thanks Chuck, i thought the values were comma separated in the array which is obviously where i've gone wrong. It seemed strange that the logs had them separated out but i guess it was identifying the next value based on its position in the array not because of any commas.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2017 06:51 AM
When you print an array, the debug statement will automatically put in the commas, which is misleading, but necessary to make it somewhat human readable.