The CreatorCon Call for Content is officially open! Get started here.

How to write email script to print assigned to or assignment group

PRAGHATIESH S
Tera Expert

In the email template, I need to print when assigned to available print assigned to (Dear assigned_to). If assigned to not available print assignment group (Dear assignment_group). How to write email script for this condition

3 REPLIES 3

Murthy Ch
Giga Sage

Hi @PRAGHATIESH S 

Try something like below:

//Assuming notification is on the same table

if(current.assigned_to != "")
template.print("Dear "+ current.assigned_to.name.toString() +",");
else
template.print("Dear "+current.assignment_group.name.toString() +",");
Thanks,
Murthy

Gunjan Kiratkar
Kilo Patron
Kilo Patron

hi @PRAGHATIESH S 

You can try below script

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {
	if(current.assigned_to!=''){
    template.print("Hi "+current.assigned_to.first_name+",<br/>");
	}else{
		template.print("Hi "+current.assignment_group+",<br/>");
	}
	
	

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

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

SUBHAM AGARWAL
Tera Guru

Hello,

You can also write a BR and trigger an event to send the notification. You can pass the value of assigned to or assignment group as property.

 

Thanks