how add a button in email notification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2021 06:47 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2023 03:06 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2023 10:52 PM
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.
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:
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.
Shivam Jaiswal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2023 02:36 AM
Hello @samadam ,
Did you get a chance to try this one?
Please mark it helpful & correct if it works as required.
Shivam Jaiswal