The CreatorCon Call for Content is officially open! Get started here.

how add a button in email notification

samadam
Kilo Sage

I am trying to send email when an approval is inserted for a non task table in a scoped app, I created a notification. How can I add a button to say "Agree to the conditions" which would work like approval and update approval state on the record?

 

Thanks

7 REPLIES 7

Hello Ujjwal,

Thank you for above stepwise execution.
In my case, the email script which I have written is fetching aggregated overdue requests for individual approvers. In the source code I have added a button called "Click here" to approve all the overdue requests in one go. So the button should redirect to a portal, where each individual can see their own requests and the portal already has approve/reject button configured. But I am not able to add a link to this button as the portal includes a data widget and some extra filter has to be added too while fetching the requests to the individual approvers. 

Shivam Techlene
Tera Guru

Hello @samadam,

 

You'd need three things in place to achieve this requirement.

1. Email Notification

2. Notification Email Script

3. Display Business rule

 

Step 1: Configure an email notification record on sysapproval_approver table and include an email script inside it.

 

Screenshot 2023-11-06 at 12-01-02 Catalog Task Approve_Reject Notification ServiceNow.png

 

Screenshot 2023-11-06 at 12-01-17 Catalog Task Approve_Reject Notification ServiceNow.png

 

Screenshot 2023-11-06 at 12-02-41 Catalog Task Approve_Reject Notification ServiceNow.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Step 2: Configure a notification email script with the same name you've used under notification body inside ${mail_script:<name_of_email_script>

 

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

    var baseURL = "https://" + gs.getProperty('instance_name') + ".service-now.com/sysapproval_approver.do?sys_id=" + current.sys_id;
    var approveURL = "https://" + gs.getProperty('instance_name') + ".service-now.com/sysapproval_approver.do?sys_id=" + current.sys_id + "&parm1=approve";
    var rejectURL = "https://" + gs.getProperty('instance_name') + ".service-now.com/sysapproval_approver.do?sys_id=" + current.sys_id + "&parm1=reject";

    //button styling
    var buttonStyle = 'border: none; border-radius: 10px; color: white; padding: 15px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer;';
    var blueButtonStyle = buttonStyle + ' background-color: #008CBA;';
    var greenButtonStyle = buttonStyle + ' background-color: #4CAF50;';
    var redButtonStyle = buttonStyle + ' background-color: #ff000A;';
    var greyButtonStyle = buttonStyle + ' background-color: #B8B8B8;';

    template.print('<a href="' + baseURL + '" style="' + buttonStyle + blueButtonStyle + '">Click here to open Approval Request</a><br/>');
    if (current.state == "requested") {
        template.print('<a href="' + approveURL + '" style="' + greenButtonStyle + '">Approve</a>');
        template.print('<a href="' + rejectURL + '" style="' + redButtonStyle + '" download>Reject</a><br />');
    } else if (current.state == "approved" || current.state == "rejected") {
        template.print('<a href="#" style="' + greyButtonStyle + '">Approve</a>');
        template.print('<a href="" style="' + greyButtonStyle + '" download>Reject</a>');
        if (current.state == "approved") {
            template.print("<br>This Request is already in approved state");
        } else if (current.state == "rejected") {
            template.print("<br>This Request is already in rejected state");
        }
    }

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

 

Step 3: Configure a display business rule to update the approval state.

 

Table: Approval [sysapproval_approver]

Advanced: true

 

In the advanced tab, put the code given below:

 

(function executeRule(current, previous /*null when async*/ ) {

    var currentURL = gs.getProperty("glide.servlet.uri") + gs.action.getGlideURI();
    if (currentURL.indexOf("parm1=approve") > -1) {
        current.state = "approved";
	current.update();
    } else if (currentURL.indexOf("parm1=reject") > -1) {
        current.state = "rejected";
	current.update();
    }

})(current, previous);

 

You'd be having buttons on notification like this:

Screenshot 2023-11-06 at 12-19-39 Catalog Task Approve_Reject Notification ServiceNow.png

 

You can use this OOTB layout which I've used named "Employee Notification Layout"

 

Please mark my answer helpful & correct if it helps to resolve your requirement.

 

 

Thanks & Regards,
Shivam Jaiswal

Hello @samadam ,

 

Did you get a chance to try this one?

Please mark it helpful & correct if it works as required.

 

Thanks & Regards,
Shivam Jaiswal