Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to create button using email script for Acknowledge & Reject on Email Notification without using image.

Chaitanya Redd1
Tera Guru

Hello Team,

From past Three days I was trying to create Button in place of links on email notification but it's not working showing error script on email body. I need help to create Button without using button can any one help me with the script if possible.

I have created "Acknowledge" & "Reject" links on Email Template.

I have tried by seeing few old links but's it's not working.

 

Thanks,

JRY

6 REPLIES 6

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

I don't want it using image I need it by creating button only.

 

Thanks,

JRY

Ajaykumar1
Tera Guru

Mohammad Danis1
Giga Guru

Hi Jry,

Below are portions of a script include that was called from mail scripts to print the html. I found this approach easier to manage and re-use. You can essentially drop these in a script include and call them from a mail script via a call like.

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {

// Note : I tested with passing the link of incident record you can pass approval/rejection link here.
	
	var btnapprove = 'Approve';
	var btnReject = 'Reject';
	template.print("Click here to Approve :");
	template.print(new myUtil().getButton('https://dev.service-now.com/nav_to.do?uri=%2Fincident.do%3Fsys_id%3Dd87d2b892ff090106fadde1a2799b66e%26sysparm_record_target%3Dincident%26sysparm_record_row%3D3%26sysparm_record_rows%3D40%26sysparm_record_list%3Dactive%253Dtrue%255EORDERBYDESCnumber'+'', btnapprove, 'View the record' ));
	
	template.print("Click here to Reject");
	
	template.print(new myUtil().getButton('https://dev.service-now.com/nav_to.do?uri=%2Fincident.do%3Fsys_id%3Dd87d2b892ff090106fadde1a2799b66e%26sysparm_record_target%3Dincident%26sysparm_record_row%3D3%26sysparm_record_rows%3D40%26sysparm_record_list%3Dactive%253Dtrue%255EORDERBYDESCnumber'+'', btnReject, 'View the record' ));
	
	
})(current, template, email, email_action, event);


Note : I tested with passing the link of incident record, you can pass approval/rejection link here.

Created one Script include which is client Callable : myUtil() and within that created one function with three parameters getButton(link,text,title), like :

 

//specify the link (ie https://mylink.com), the text (Button Text), and the tool tip or title text


getButton:function(link,text,title){


return '<table width="100%" border="0" cellspacing="0" cellpadding="0">'+


'<tr><td><table border="0" cellspacing="0" cellpadding="0"><tr>'+


'<td align="center" style="-webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px;" bgcolor="#37424A">'+


'<a title="'+title+'" href="'+link+'" target="_blank" '+


'style="font-size: 16px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; text-decoration: none; '+


'-webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; padding: 12px 18px; border: 1px solid #222222; display: '+


'inline-block;"><strong style="font-weight:normal;">'+text+'</strong></a></td>'+


'</tr></table></td></tr></table>';


},

 

Buttons this code generates:

find_real_file.png

 

If my reply helped with your issue, Kindly consider marking it as Correct & 👍Helpful .

Thank you!!

Kind Regards,
Mohammad Danish