Loop reference list object
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2018 02:52 AM
Hi All,
I have a table with one filed that is a list reference to another table, it would reference multiple objects.
I want to loop all object in this filed and do some work but I don't know how to do this
I tried two way below , but both were not work.
for(var item in current.items)
gs.addInfoMessage(item.id);
current.items.split(',').forEach(function(item){
gs.addInfoMessage(item.id);
});
Is there something I missed?
Any help will be appreciated.
Thanks in advance.
- Labels:
-
Personal Developer Instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2018 10:34 PM
This is untested, but the following should work
Create an array from current.items
var arr = current.items.split(",");
Then loop through it using the following:
for(var i = 0; i < arr.length; i++){
//do your thing
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2018 06:33 PM
Hi Matthew
I use
var arr = current.items.split(",");
for(var i = 0; i < arr.length; i++){
gs.addInfoMessage(arr[i].id);
}
but still get 'undefined' message
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2018 11:04 AM
Since you're trying to pull a field from the records in the list, try this:
var arr = current.items.split(",");
for(var i = 0; i < arr.length; i++){
var gr = new GlideRecord('TABLE_NAME'); //insert the table that the list field references
if(gr.get(arr[i])){
gs.addInfoMessage(gr.id);
}
}