Click Approve/Reject on email Notification

Al-jhon
Kilo Sage

Hello All,


I have a problem with approving/rejecting a Approval request using email notification.

Aljhon_0-1673328012194.png


When the 1st approver click the hyperlink "Click here to Approve/Reject", it will open and redirected to the approval form.

when the 2nd and 3rd approver click the same link, it will open and redirected to the approval form but under the 1st approver view or name.

Aljhon_1-1673328249419.png


Please help to check and correct my existing email script:

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

var baseURL = '';

baseURL = "https://" + gs.getProperty('instance_name') + ".service-now.com/sysapproval_approver.do?sys_id=" + current.sys_id;

template.print('<a style="font-family: verdana; font-size: 14px;color: blue;" href=' + baseURL + '>Click here to Approve/Reject</a><br />');


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


The link should be open and redirected under for each approver not only under the 1st approver.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Al-jhon 

your approval email notification should be on sysapproval_approver so that it sends 3 different emails for each of those 3 approver users

Condition: current.source_table == 'pm_project_task'

you can access the task fields using dot walking and show in email body

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

19 REPLIES 19

jaheerhattiwale
Mega Sage
Mega Sage

@Al-jhon I think the approval request for "Dan Kuo" is sent to all 3 approvers. The email should be sent to only "Dan Kuo". The 2nd and 3rd approvers should get different emails.

 

So please check the notification and send it to the approver only. In this way the 2nd and 3rd approvers will get there own emails and when they click on link they will be redirected to there own approval request page.

 

Please mark as correct answer if this solves your issue. 

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Hello @jaheerhattiwale ,

for further information, my email notification table is Project Task:

Aljhon_0-1673333650920.png


and it will be sent to the approver who set by a user:

Aljhon_1-1673333707821.png

and it will show on the Related list Approver:

Aljhon_2-1673333742126.png

 



@Al-jhon Ok got it. Try updating the script as below and check.

 

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

    var approver = new GlideRecord("sysapproval_approver");
    approver.addQuery("sysapproval="+current.sys_id.toString());
    approver.addQuery("approver="+gs.getUserID());
    approver.query();

    if(approver.next()){
        var baseURL = "https://" + gs.getProperty('instance_name') + ".service-now.com/sysapproval_approver.do?sys_id=" + approver.sys_id.toString();

        template.print('<a style="font-family: verdana; font-size: 14px;color: blue;" href=' + baseURL + '>Click here to Approve/Reject</a><br />');
    }
})(current, template, email, email_action, event);
 
Please mark as correct answer if this solves your issue.
Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Nootan Bhat
Kilo Sage

hi @Al-jhon,

Trigger the approval from sysapproval_approver table when record is created for specific document_id.

This way you can send separate emails to each approvers. For each users specific approval record present so single link will not work in this case. If you still wish to use the single email, you can show the list view of the record using below URL:

baseURL = "https://" + gs.getProperty('instance_name') + ".service-now.com/sysapproval_approver_list.do?sysparm_query=approverDYNAMIC90d1921e5f510100a9ad2572f2b477fe%5Edocument_id%3D" + current.sys_id;

 

Or else you can use the email template in your email and create and inbound email action or inbound flow trigger to approve the same once approvers send the approval email.

Refer: https://developer.servicenow.com/dev.do#!/learn/learning-plans/tokyo/new_to_servicenow/app_store_lea...

 

Let me know if it helped.

 

Thanks

Nootan