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 thank you, this does now pick up all assets assigned to the user.

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

@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

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: 

heathers__0-1700154799040.png

 

@Moedeb 

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

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

@Ankur Bawiskar 

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.