0

Write Scheduled Job: Approval Remainder

var arrUtil = new ArrayUtil(); //set up array to find all pending approvals for users
 var answer = [];
var UserName = [];
 var app = new GlideRecord('sysapproval_approver'); //set up variable to retrieve approvals that are pending
app.addEncodedQuery("stateINrequested^sys_created_onRELATIVELT@hour@ago@24");
app.orderBy('approver');
app.query();
while (app.next()) { // step through the approvals one by one
    if (arrUtil.indexOf(answer, app.approver.sys_id) == -1) { //if the approver is not currently in our list, add them (next line adds them)
        answer.push(app.approver.sys_id);
        UserName.push(app.approver.getDisplayValue());
    }
}
for (var i = 0; i < answer.length; i++) { //have array that lists each user who has open change approvals We'll step through each
    gs.eventQueue('approval.remainder', app, answer[i], UserName[i]); //and fire off the event for each user, passing their sys_id as parm1
 }

Create Event:

Go to registry in left navigation bar: approval.remainder

Create Notification:

When to fire when event trigger: give event name : approval.remainder

Notification Email Script:

var html = '';
 html += "<table border='1px solid #ce2127' style='font-size: 10pt;'><tr><th style='text-align:center'><b>Request Date</b></th><th style='text-align:center'><b>Requestor</b></th><th><b>Short Description</b></th><th><b>Request ID</b></th><th><b>Approve/Deny</b></th></tr>";
var app = new GlideRecord('sysapproval_approver'); //create a query to retrieve open approvals
app.addEncodedQuery("stateINrequested^sys_created_onRELATIVELT@hour@ago@24");
app.addQuery('approver', event.parm1); //only find approvals for the current approver     
app.query();
while (app.next()) {
 var requestorName="";
 var getApprovalName=app.sysapproval.getDisplayValue();
 if(getApprovalName.indexOf("RITM")!=-1)
  {
   requestorName=app.sysapproval.requested_for.getDisplayValue();
  }
 else
  {
   requestorName=app.sysapproval.requested_by.getDisplayValue();
  }
    var link = gs.getProperty('instance_name');
    var generateLink = 'https://' + link + '.service-now.com/sp?id=approval&table=sysapproval_approver&sys_id=' + app.sys_id;
    var anchor = "<a href=" + generateLink + ">Approve / Deny</a>";
    html +="<tr><td><b>" + app.sysapproval.sys_created_on.getDisplayValue() + "</b></td><td><b>" + requestorName + "</b></td><td>" + app.sysapproval.short_description + "</td><td><b>" + app.sysapproval.getDisplayValue() + "</b></td><td>" + anchor + "</td></tr>";
}
html += '</table>';
template.print(html);

Schedule job to send notification Remainder after 24 hours of ticket creation ServiceNow
Working Code Edited question July 13, 2023