
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 12:04 AM
I am wanting to do something very similar to the solution listed in the following article
What I want to do is send an email to all users that lists all assets that are assigned to them.
I'm guessing I could trigger a email notification via a business rule or an event (this is something that could be a one off or at least used only very occasionally)
I want it to go through each user, add their assets, send the email, move onto the next user, once all have been emailed stop!
The link above does not work for me as it pretty much generates an email with every single asset listed on it, nothing specific to an individual user.
Does anyone know how I can do this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2020 01:46 AM
It should look like this in script
(function runMailScript(current, template, email, email_action, event) {
var user = event.parm1;
var arr = [];
var gr = new GlideRecord('cmdb_ci'); // table name changed
gr.addQuery('assigned_to', user);
gr.query();
while(gr.next()){
var str = gr.asset_tag + ' - ' + gr.name + ' - ' + gr.model_id.getDisplayValue();
arr.push(str.toString());
}
template.print('<ul>');
for(var i=0;i<arr.length;i++){
template.print('<li>' + arr[i] + '</li>')
}
template.print('<ul>');
})(current, template, email, email_action, event);
I hope this will help and answer will be marked as correct and helpful as most of the information is already shared.
Have nice day
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2020 11:17 PM
I'm sorry to ask this again after all your help, but how would I add multiple fields so the asset has a decent description for the user to understand exactly what asset it is that is being described?
EG, I'd like to have the following fields
asset_tag + name + model_id
So it would display something like this
R01234 - Headset - Jabra Wireless Engage 65
Also for some reason it still adds an extra dot on the next line after the last asset?
I really do appreciate your help on this sooo much
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2020 01:46 AM
It should look like this in script
(function runMailScript(current, template, email, email_action, event) {
var user = event.parm1;
var arr = [];
var gr = new GlideRecord('cmdb_ci'); // table name changed
gr.addQuery('assigned_to', user);
gr.query();
while(gr.next()){
var str = gr.asset_tag + ' - ' + gr.name + ' - ' + gr.model_id.getDisplayValue();
arr.push(str.toString());
}
template.print('<ul>');
for(var i=0;i<arr.length;i++){
template.print('<li>' + arr[i] + '</li>')
}
template.print('<ul>');
})(current, template, email, email_action, event);
I hope this will help and answer will be marked as correct and helpful as most of the information is already shared.
Have nice day
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2023 09:13 AM
Hello, this worked great. Is there a way to add a hyperlink to catalog item in each asset that is printed?
Is there a way to remove the extra "dot" in the email?
EX:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2020 01:17 AM
Let me know if that answered your question.
If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2020 03:46 PM
Thank you so much for all your help, I wish I could do more than just mark as helpful and mark as correct. It seriously is very much appreciated.