Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Jaspal Singh
Mega Patron
Mega Patron

OOB notifications for Approval includes links for approval as below.

find_real_file.png

These seems to be bringing more of standard user interface however, ServiceNow provides us a functionality of mail scripts that can be customized & leverged to an extent so as to display dynamic button/images instead of standard links which is also very simple to build.

find_real_file.png

Steps below can be followed for getting something as above in place.

1. Upload images as attached in the Images table from System UI >> Images.

2. Create mail scripts as below for Approve & Reject options.

    a. Approve: email.button.approve.insert

var img = "/Approve.png";

var response = "approve";

var emailbod = "I approve this request.";

template.print(renderMailtoButton(img, response, emailbod));

 

  b. Reject: email.button.reject.insert

var img = "/Reject.png";

var response = "reject";

var emailbod = "I reject this request.";

template.print(renderMailtoButton(img, response, emailbod));

 

3. Script include: renderMailtoButton

function renderMailtoButton(image, response, emailbod){
	
	var instance = gs.getProperty("instance_name");
	var link = "https://" + instance + ".service-now.com";
	var mark = email.watermark;
	var number = current.number;
	var emailAddress = instance + "@service-now.com";
	if (current.getTableName().indexOf("sysapproval") != -1){
		number = current.sysapproval.number;
		}
			var mailLink = '<a href="mailto:'+ emailAddress + '?subject=Re:' + number + ' ' + response +'&body=' +  emailbod +  mark + '"><img src="' + link + image + '"></a>';
	return mailLink;
	
}

Script include above will help associating image (approve/reject), subject, body & recipient which is called in the mail script.

renderMailtoButton is used to set below when Approve button is clicked.

To: (instance mail),

Subject: RE: RITM000000 approve

Body: I approve this request.

find_real_file.png

On click of Reject button from Approval mail below is set.

To: (instance mail),

Subject: RE: RITM000000 reject

Body: I reject this request.

find_real_file.pngTo summarize, renderMailtoButton is used to open outlook mail directly with the values being passed in Image, Subject, Body & recipient list.

4. Call the mail scripts in the notification body (What it will contain) so as to make it work in the format as below.

 

 

Dear ${approver.name},

Please approve or reject by clicking one of the buttons below and sending the email opened after click of any of below button.

${mail_script:email.button.approve.insert} ${mail_script:email.button.reject.insert}

Output as below:

find_real_file.png 

 

Hope it helps.

 

Thanks,

Jaspal Singh

83 Comments