DEV Community


Posted on • Updated on

ServiceNow: scheduled job, sending a reminder for approvals

I needed to write a scheduled job, which sends out a reminder notification to the approving person for an approval every x days.

The integer for the days is saved as a property. On the approval table I added a field called 'u_reminder_date' which is filled, when the approval is created. The reminder shall only be send for approvals that are either for requests or requested items. Here I learned, that the addQuery 'INSTANCEOF' can be used perfectly!

Following is the full script:

var approvalGR = new GlideRecord('sysapproval_approver');

approvalGR.addQuery('state', 'requested');
approvalGR.addQuery('sysapproval.sys_class_name', 'INSTANCEOF', 'sc_req_item');


var reminderDate = new GlideDateTime();


while ( {
    gs.eventQueue('reminder.notification', approvalGR, approvalGR.approver.getValue('email'), '');

Enter fullscreen mode Exit fullscreen mode

It can also happen, that a user writes a comment, that he needs more time for the approval. In that case, I added a business rule on the approval table, which is fired then a comment is made. When the commenter is the same as the approver, the reminder date is push back for x days.

if (gs.getUserID() == current.getValue('approver') && current.state == previous.state) {

        var currentDate = new GlideDateTime();
Enter fullscreen mode Exit fullscreen mode

Top comments (0)