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.

approve button link to reply-to email window

Servicenow10
Kilo Guru

hi 

i have designed a notification which looks like this:

 

find_real_file.png

 

now what i need to do is once i click on approve button it  open a reply-to email window. Just Click 'Send' to forward the email back to ServiceNow and approve the request. The reply email is linked directly to the approval request in ServiceNow and it will look like below image

 

 

find_real_file.png

how can i achieve this through email script or any other way......please explain me in detail as am new to now and scripting

 

thanks in advance!!

1 ACCEPTED SOLUTION

Omkar Joshi
Giga Guru

Hi,

Use the below code in email script

 

 

 

(function runMailScript(current, template, email, email_action, event) {

var apButStr = '<div><a href="mailto:dev11111@service-now.com?subject=re:' + current.number + ' - approve&body='+ current.number + ' - approve' +'"><br /><img style="align: baseline;" title="Click this button to mark approved" src="/approveButton.pngx" alt="Approved" width="142" height="41" align="baseline" /></a>';

var rejButStr = '<a href="mailto:dev11111@service-now.com?subject=re:' + current.number + ' - reject&body='+ current.number + ' - Reject' +'"><img style="align: baseline;" title="Click this button to mark rejected" src="/rejectButton.pngx" alt="Rejected" width="142" height="41" align="baseline" /></a></div>';

var full = apButStr + rejButStr;

template.print(full);

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

 

 

Note:Use your instance URL.

View solution in original post

16 REPLIES 16

ok..i will share you code and the inbound action steps.

Follow the Steps:

Go to the inbound action and create new.

 

d

 

Add below script:

 

var number = email.subject.substr(3,11);
var item_id='';

var item=new GlideRecord('sc_req_item');
item.addEncodedQuery('number='+number);
item.query();

if(item.next())
{
item_id=item.getValue('sys_id');
}

var apr=new GlideRecord('sysapproval_approver');
apr.addEncodedQuery('document_id='+item_id);
apr.query();

while(apr.next())
{
if(email.subject.indexOf("approve") > -1)
{
apr.state='approved';
}
else if (email.subject.indexOf("reject") > -1)
{
apr.state='rejected';
}
apr.update();
}

i did the above changes and its not updating the approval column to  approved/rejected

you have mentioned this in your code and i want to update approval column in my form

apr.state='approved';

 

where am going wrong and thanks for all these efforts

Can you please share screenshot where you want to change?

please check the below image

 

find_real_file.png

 

i want to update this field when i rejected this it shows approved only which was by default and one more doubt

 

as you can see the approve link i want to keep space between two buttons and i will share the html code

 

 

find_real_file.png

 

 

html code for notification:

 

<h2>Request approval Mail</h2>
<style>

h2
{
color: white;
background-color: #6699CC;
margin: 20px 2px;
padding: 15px 45px;
text-align: left;


}

table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
margin: 20px 2px;


}

td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 2px;
background-color: #dddddd;
}

.button {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}

.button2 {
background-color: #ff0000; /* red */
margin: 32px 150px;
}


body {background-color: white;}
h1 {color: white;}
p {color: black;}
</style>
<p>Hi Steve,<br /><br />You have been sent request for approval.</p>
<p>&nbsp;</p>
<table>
<tbody>
<tr>
<td>Name</td>
<td>abel&nbsp;</td>
</tr>
<tr>
<td>RITM number</td>
<td>RITM0010002</td>
</tr>
<tr>
<td>Priority</td>
<td>4 - Low</td>
</tr>
<tr>
<td>Requested For</td>
<td>abc</td>
</tr>
<tr>
<td>Requested By</td>
<td>xyz</td>
</tr>
<tr>
<td>Status</td>
<td>Approved</td>
</tr>
</tbody>
</table>
<p>Please approve or reject this request using the buttons below</p>
<p>when rejecting an access request,please include the reason for rejection in the response email.</p>
<p>&nbsp;</p>
<p>${mail_script:test}&nbsp;</p>
<p><button class="button">Approve</button> <button class="button button2">Reject</button></p>
<p>&nbsp;</p>
<p>&nbsp;</p>