Need to get all the hardware assets assigned to user in an email notification on the workflow

kamal11
Giga Expert

Hi All,

we have a requirement wherein we need to get all the asset's assigned to a person in an email notification.

If he has multiple assets, all the assets should be in the email.

It should be in the folowing way

"Below are the assets assigned to ${variables.assigned_to}."

Asset 1:

Asset 2       "

Can you help me in achieving this through the workflow notification

Thanks,

Kamal

1 ACCEPTED SOLUTION

Mr_Vin
Kilo Expert

Create a Email script like below and use this mail script in the notification.


1. go to system Notification --> Email --> Notification Email Scripts



Name: user_assets


Script:



(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,


/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,


/* Optional GlideRecord */ event) {



var gr = new GlideRecord('cmdb_ci_computer');


gr.addEncodedQuery('assigned_to', current.<user field>);


gr.query();


while(gr.next()){


template.print(gr.name+'<br/>');


}



})(current, template, email, email_action, event);




2. Go to System Notification --> Email -->Notifications


create a notification with Message Html( under 'What it will contain' tab) as below.



<add content as you wish..>


user assets are :


${mail_script:user_assets}


View solution in original post

9 REPLIES 9

nitin_kumar
Mega Guru

Hi Kamal,



You can create a mail script and use GlideRecord to 'alm_asset' table. Check the following link


Scripting for Email Notifications - ServiceNow Wiki



Thanks,


Nitin.



Hit Like, Helpful or Correct based on the impact of the response


Hi Nitin,



Is there a way where in we can get a solution in the workflow notification itself?



Thanks,


Kamal


No, you have to create a mail script and call the mail script from the Notification.



Thanks,


Nitin.



Hit Like, Helpful or Correct based on the impact of the response


Mr_Vin
Kilo Expert

Create a Email script like below and use this mail script in the notification.


1. go to system Notification --> Email --> Notification Email Scripts



Name: user_assets


Script:



(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,


/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,


/* Optional GlideRecord */ event) {



var gr = new GlideRecord('cmdb_ci_computer');


gr.addEncodedQuery('assigned_to', current.<user field>);


gr.query();


while(gr.next()){


template.print(gr.name+'<br/>');


}



})(current, template, email, email_action, event);




2. Go to System Notification --> Email -->Notifications


create a notification with Message Html( under 'What it will contain' tab) as below.



<add content as you wish..>


user assets are :


${mail_script:user_assets}