
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2022 10:57 AM
I'm trying to iterate through each item in the related list of a record to check if a certain value is present but am getting stuck at the first hurdle
I have a related list of locations on the incident table.
This table seems to use a field called Task to reference the Incident.
I have a Business Rule which is trying to iterate through the list to query some of the columns and vales, but it doesn't seem to be outputting anything in the log.
(function executeRule(current, previous /*null when async*/ ) {
gs.log('stage 1');
var gr = new GlideRecord('task_location');
gr.addQuery('task', current.sys_id);
gr.query();
if (gr.hasNext()) {
gs.info('stage 2');
gs.info(gr.location.sys_id);
gs.info(gr.incident.sys_id);
}
})(current, previous);
What seems to be the issue at hand here?
Is there a better way to go about this?
Solved! Go to Solution.
- Labels:
-
Script Debugger

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2022 11:04 AM
Hey,
Try updating it a little bit:
var gr = new GlideRecord('task_location');
gr.addQuery('task', current.getUniqueValue());
gr.query();
while (gr.next()) {
gs.info('stage 2');
gs.info(gr.getValue("location"));// this will give you sys_id of location, if you want name try gr.location.name.toString()
gs.info(gr.getValue("task"));// its a task field, not incident
}
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions 🙂
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2022 11:04 AM
Hey,
Try updating it a little bit:
var gr = new GlideRecord('task_location');
gr.addQuery('task', current.getUniqueValue());
gr.query();
while (gr.next()) {
gs.info('stage 2');
gs.info(gr.getValue("location"));// this will give you sys_id of location, if you want name try gr.location.name.toString()
gs.info(gr.getValue("task"));// its a task field, not incident
}
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions 🙂
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2022 01:54 AM
Worked a charm!
Thanks 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2022 08:34 PM
Awesome 🙂
Aman Kumar