How to send Approval Reminders?

shane_holland
Mega Contributor

Can someone explain how I can set-up approval reminders to automatically be sent out daily? I am mostly interested in reminders for requests in the Service Catalog, but if it cannot be scoped to that, then any approval reminders will do? I can't believe this isn't an OOB scheduled job in ServiceNow...

 

Thank you,

Shane

1 ACCEPTED SOLUTION

Hi Shane,



Since you have written the email notification in the sysapproval table, better you query sysapproval itself in the scheduled job. Please check the code below given by Bhavesh, its checking if the approval is for catalog request and whether the request is still in requested state. Please make sure you change the event name in the below code to the one you already have, it will look like this:-



var gr = new GlideRecord('sysapproval_approver');  


      gr.addQuery('state', 'requested');  


      gr.addQuery('sysapproval.sys_class_name','sc_request');  


      gr.query();  


      while (gr.next()) {  


          gs.eventQueue("catalog_task_approval_reminder",gr, gs.getUserID(), gs.userName());  


      }  



In the email notification,for Who will receive, make Users/Groups in fields as 'Approver', it should work fine. Also make sure that you check the 'Send to event creator', its just for testing you can deactivate later.



Thanks & Regards,


Hari


View solution in original post

10 REPLIES 10

This works! I actually changed the query because I want to query on sc_req_item the more I thought about it and it works just fine. Much appreciated.


How to apply filter/ write script to trigger event for a particular catalog item approval reminder ?

Bhavesh Jain1
Giga Guru

Try this code in your job:



var app = new GlideRecord('sysapproval_approver');


app.addQuery('state', 'requested');


app.addQuery('sysapproval.sys_class_name','sc_request');


app.query();


while (app.next()) {


  gs.eventQueue("sc_request_reminder",app, gs.getUserID(), gs.userName());


}



Regards,


Bhavesh


IGate-logo.png


http://www.igate.com


Thank you for the code Bhavesh! This works supplemented with the event generation and e-mail notification that Hari helped me with earlier.


Subhajit1
Giga Guru

Hi Shane,


Add this script to Scheduled Script Execution:-


This will send 3 day old pending Approval reminders.


You can configure this for any duration you like.




remindApprovers();



function remindApprovers()


{


var appr = new GlideRecord('sysapproval_approver');


appr.addEncodedQuery('state=requested^sysapproval.active=true^sysapproval.sys_class_name=sc_req_item^sys_updated_onRELATIVELE@hour@ago@72^sys_created_onRELATIVEGE@hour@ago@96');


appr.query();


var last_approver;


while (appr.next())


{


if(last_approver != appr.approver.toString())


{


gs.eventQueue("approval.reminder.req", appr, gs.getUserID(), gs.getUserName());


}


last_approver = appr.approver.toString();


}


}



Thanks,


Subhajit