Email Notification to all users of assets assigned specifically to them

Moedeb
Tera Guru

I am wanting to do something very similar to the solution listed in the following article

https://community.servicenow.com/community?id=community_question&sys_id=f4f4c72ddbd8dbc01dcaf3231f96...

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?

 

1 ACCEPTED SOLUTION

@Moedeb 

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

19 REPLIES 19

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Do you require single email per user with the list of assets assigned to that user?

OR

Do you want single email per asset

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

A single email per user with the list of assets assigned to that user

Hi,

In that case you need to GlideRecord that table and group by assigned_to field

In the email script you need to get all the assets assigned to that user

Regards
Ankur

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Ankur Bawiskar sorry that doesn't really help. I knew that from looking at the link I provided, but as I said that listed every single asset that is in the table.

It also doesn't tell me how to send to each user one after the other.