
- 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-06-2020 12:19 AM
Thank you.
Happy learning
Regards
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-14-2020 05:28 AM
where job script need to write either schedule jobs or script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2020 05:49 AM
Hi,
I have provided sample script to your question
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
‎07-28-2020 01:45 AM
Hi
1. Create a event on asset table
2. Write a script (fix script) and get all unique assigned users of assets and trigger event for each assigned user
var gr = new GlideRecord("alm_asset");
gr.addEncodedQuery("assigned_toISNOTEMPTY");
gr.query();
var users = [];
while(gr.next()) {
users.push(gr.assigned_to.toString());
}
var arrayUtil = new ArrayUtil();
users = arrayUtil.unique(users);
//Here now either you can trigger 1 event and send all users as 1 string and parse them inside mail script. But if the string is bigger, it might break
//so triggering event per user as its easier to track
for(i=0;i<users.length;i++) {
gs.print(users[i]);
gs.eventQueue("your_event_name",current,users[i],gs.getUserName());
}
3. Create a notification which listen to yoru event
4. Then inside notification, add mail script and add below code.
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var gr = new GlideRecord('alm_asset');
gr.addEncodedQuery('assigned_to', event.parm1);
gr.query();
while(gr.next()){
template.print(gr.name+'<br/>');
}
})(current, template, email, email_action, event);
Mark the comment as a correct answer and also helpful if this answers your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2020 12:00 PM
Hi,
If this has answered your question, mark the comment as a correct answer and helpful.