0% found this document useful (0 votes)
2K views14 pages

Approve-Reject Button in Approval Notification - IT Service Management - Blog

The document describes how to customize approval notifications in ServiceNow to include 'Approve' and 'Reject' buttons that open emails when clicked instead of standard links. It provides code for mail scripts and an include script to render mailto links with images, subjects, bodies and recipients. Comments discuss issues and improvements to the approach.

Uploaded by

Christopher P
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views14 pages

Approve-Reject Button in Approval Notification - IT Service Management - Blog

The document describes how to customize approval notifications in ServiceNow to include 'Approve' and 'Reject' buttons that open emails when clicked instead of standard links. It provides code for mail scripts and an include script to render mailto links with images, subjects, bodies and recipients. Comments discuss issues and improvements to the approach.

Uploaded by

Christopher P
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

!

Blog

Approve/Reject button in Approval noti3cation


by Jaspal Singh Forum Level 10
created 3y ago (edited 2y ago) in IT Service Management

OOB notiAcations for Approval includes links for approval as below.

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.

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
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.
On click of Reject button from Approval mail below is set.
To: (instance mail),
Subject: RE: RITM000000 reject
Body: I reject this request.

To 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 notiAcation 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

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

Output as below:
:
 
 
Hope it helps.
 
Thanks,
Jaspal Singh

Approve.PNG Reject.PNG
PNG PNG
10.12K 8.81K

Topics: Change Management Service Catalog


Version: Multiple Versions

" Helpful (29) # Comment (55) 14587 Views

55 Comments Show All Comments

Milind Apte • 3y ago

Dear Jaspal,
Thanks for sharing code, this is deAnitely user friendly and customers were looking for. I have
replicated on my personal instance and it's working as mentioned in the blog.
Thanks,
Milind
:
" Helpful (2) # Comment

Roshani • 2y ago
R

Hi Jaspal ,
 
I am not able to get these button on notiAcation .  Here is my code 
 

 
 
:
" Helpful (0) # Comment

$ Show comments

Uma • 2y ago
U

Hi Jo
 i have an requirement to create a database views based on cmdb_rel_ci table.
Current relationship records are stored as the following:
Parent = Environment, Type = Depends On::Used By, Child = Hardware
Parent = Business Application, Type = Depends On::Used By, Child = Environment
 
Create a Database view joining cmdb_ci_appl, cmdb_ci_business_app,
and cmdb_ci_environment based on cmdb_rel_ci relationships.
i have created below Database view.after adding 4th table its giving empty records.
 
:
do you have any idea how to get all the relationship data means from app to env and env to
server. i need to get all the data.
let me know if you have any idea.
Thanks in advance.

" Helpful (0) # Comment

Michael • 2y ago

Hi Jaspal, 
 
This is great! Thank you for sharing this.  We found one issue however during our testing.  I'm
hoping you can correct/update your steps above as it could lead to unintended approvals. 
For step:
    b. Reject:
Reject: email.button.reject.insert
You have:
    var response = "approve";
Should be:
    var response = "reject";
 
Thanks, 
Michael

" Helpful (0) # Comment

$ Show comments

Robert Duca • 2y ago


RD

Is there a way to force a carriage return / newline int he email body? It runs the watermark right
up against the 'I approve' message in the email body:
 
:
" Helpful (0) # Comment

$ Show comments

Freddy • 2y ago
F

Hi @Jaspal Singh ,
how can I change the body of the email on this script to use email template?

var emailbod = "I reject this request.";

I want the message as per below to be once the user click approve or reject. Is it possible to do
so?
==============================================================
Please do not modify the subject of this email. Click 'Send' to automatically approve this
request.
Comments can be added below.
 
Dear "User"
This request has been approved by:
"Manager"
Comments (Customer visible): 
 
WHAT HAPPENS NEXT:
Service Desk will be in touch once this request has been actioned.
==============================================================
:
" Helpful (1) # Comment

$ Show comments

Freddy • about a year ago


F

Hi @Jaspal Singh , 
Would you know how to get the response email to go to sysapproval_approver table?
When the user reply with subject line Re:creq12323 - Approve, the response goes to the ticket
itself.
 
Thanks so much in advanced.

" Helpful (0) # Comment

Edxavier Roberto Caez • about a year ago


ERC

Hi, it would be possible to add a third option? Instead or Approve or Reject add a new option
Review (This option would re-open a task)

" Helpful (0) # Comment

$ Show comments

amIT • about a year ago

Hi Jaspal @Jaspal Singh 


 
Blog was super supportive, please make the some adjustment in the
 
2. Create mail scripts as below for Approve & Reject options.
:
    a. Approve:
Approve: email.button.approve.insert
 
var img = "/Approve.png";
 
please change to : var img = "/Approve.pngx";
 
SAME FOR : 
 
 b. Reject:
Reject: email.button.reject.insert
 
var img = "/Reject.png";
 
TO
 
var img = "/Reject.pngx";
 
By making this changes  this blog will be totally updated :)
 
Please mark helpfull :)

" Helpful (1) # Comment

$ Show comments

Balaraju K B • about a year ago


BKB

Hi @Jaspal Singh 
I have the similar type of requirement but it don't have any approvals and all.
For a case when an assigned to a Group there a notiAcation will be sending that will contain
"Accept" or "Reject" buttons on-click of let's say "Accept" then it should open seperate mail box
as shown above by you and that message in the body should get updated in the Additional
comments Aeld on the case.
Note : I used your script as is and uploaded images in system ui but it's not displaying the
buttons on the notiAcation body?
:
What changes i should make to get proper output here?
Anyone suggest would help a lot
 
Thanks in Advance
Balaraju

" Helpful (0) # Comment

$ Show comments

sandeep • about a year ago


S

We can do without reply email. When we click Approve and reject button . Incident should be
open and close.can we do without reply mail??

" Helpful (0) # Comment

Vijay • 8mo ago


V

Hi Jaspal,
The article is very helpful, but I get output as
Subject :-Re:RITM0010710+reject
Email body :-I+reject+this+request. In both scenario,Can you please tell me why + sign is occure

" Helpful (0) # Comment

$ Show comments

Max Lin • 3mo ago


ML

I am not an expert in ServiceNow. I used all information here including every commenter's script
and screenshot. 
:
Following Malani Arjun's Screenshot, the include script is wrong. I wasted 3 hours solving this.

Conclusion:  
Remove this code that is automatically injected by ServiceNow when you create new Include
Script. 

var renderMailtoButton = Class.create();


renderMailtoButton.prototype = {
initialize: function() {
},

type: 'renderMailtoButton'
};

 
Just directly insert below into the included script.

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:'
return mailLink;

" Helpful (0) # Comment

Gagan • 6d ago
G

Dear Jaspal, 
This is a great article and works perfect!! Thank you.
 
:
Regards,
Gagan k

" Helpful (0) # Comment

 
:
 

Contact Us % & ' (

Help
Terms of Use
Privacy Policy
Cookie Preferences
Trademark and Branding
ServiceNow Support
Knowledge Base

© 2022 ServiceNow. All rights reserved.


:

You might also like