Notification Email Script that loops through the values of the record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-14-2023 11:33 AM - edited ‎12-14-2023 11:33 AM
I'm curious if I'm able to do this. I want to create an notification email script. That retrieves the device(s) assigned to someone in my comp_device table. However, in my table a person can be assigned multiple devices. Each device being its own record with the assigned_to column being the link between all the records. If they have one or more device(s) they are assigned I want to list them out.
Example - Notification email script
var device = [];
email. setSubject('Your assigned Devices');
gr = new GlideRecord('comp_device');
gr.addQuery('assigned_to'. current.assigned_to);
gr.query();
while(gr.Next()){
device = gr.device_name;
}
var device_list = device.join('\n');
template.print('The list below are the device(s) assigned to you.');
template.print('Your Devices');
template.print(device_list);
Output:
Hello "name",
The list below are the device(s) assigned to you.
Your Devices
Device 1
device 2
Am I thinking about this correctly?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-14-2023 05:11 PM
Yes, that's exactly the approach I would use. Are you having any problems with it?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-14-2023 05:18 PM
HI @Khill Just one change bold line, you need to push array
var device = [];
email. setSubject('Your assigned Devices');
gr = new GlideRecord('comp_device');
gr.addQuery('assigned_to'. current.assigned_to);
gr.query();
while(gr.Next()){
device.push(gr.getValue('device_name')); //assuming not a reference field
}
var device_list = device.join('\n');
template.print('The list below are the device(s) assigned to you.');
template.print('Your Devices');
template.print(device_list);
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-14-2023 05:34 PM
Hi @Khill , The script provided by Harish should work, but there seems to be a type error on line 4, please check.
var device = [];
email. setSubject('Your assigned Devices');
gr = new GlideRecord('comp_device');
gr.addQuery('assigned_to'. current.assigned_to); // Change it to gr.addQuery('assigned_to', current.assigned_to);
gr.query();
while(gr.Next()){
device.push(gr.getValue('device_name')); //assuming not a reference field
}
var device_list = device.join('\n');
template.print('The list below are the device(s) assigned to you.');
template.print('Your Devices');
template.print(device_list);
Thanks,
Sunil