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

I think it would be better if he uses 'alm_asset' in the GlideRecord instead of 'cmdb_ci_computer' because they might have mobile phones too.



Thanks,


Nitin.



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


Yes Nitin, Thanks!


Hi Vinod,



I have tried the same,



But it is coming as undefined



i used below code in mail script


(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', current.variables.person1);


gr.query();


while(gr.next()){


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


}



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


Hi Kamal,



Can you change the script as I have mentioned below



var gr = new GlideRecord('alm_asset');


gr.addQuery('assigned_to', current.variables.person1);


gr.query();


while(gr.next()){


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


}



Thanks,


Nitin.



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


oops, typo there! Please check Nitin reply !