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

mamann
Mega Guru

Hi Shane,



You can definitely do this. Here's an article already on the community forums that gives good direction on accomplishing this.



Approval reminder notification to the approver with list of all his approval


harikrish_v
Mega Guru

Hi Shane,



You can create a Scheduled job for this, schedule it to run everyday and send out email reminders to all the approvers. You can write something like this in the Job:-



var gr = new GlideRecord('sc_request');


gr.addQuery('active', true);


gr.addQuery('approval','Requested'); //you can change this as per your requirement


//add couple of queries to filter the list of records returned


gr.query();


while (gr.next()) {


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


}


Here catalog_task_approval_reminder is an event. You will have to create an email notification and tie it with this event so that it gets fired when you call the event.



Hope this helps



Thanks & Regards,


Hari


.


Hi Hari,



I added the Scheduled Job, created the Event and made an e-mail notification. When I executed the   Scheduled Job, I received all errors saying "approver" is not defined in my logs. Is my e-mail notification set-up correctly?



Table: Approval [sysapproval_approver]


Send when: Event is fired


Event name: catalog_task_approval_reminder


Who Will Receive: Approver



Thanks,


Shane



P.S. Here are the logs:



23-06-2014 1:59       Warning       org.mozilla.javascript.EcmaError: "approver" is not defined.


Caused by error in <refname> at line 1



==> 1: approver



[View]         23-06-2014 1:59       Error       java.lang.NullPointerExceptioncom.glide.notification.cmn.NotificationRecipientsBuilder.splitFieldList(NotificationRecipientsBuilder.java:373)


com.glide.notification.cmn.NotificationRecipientsBuilder.getSpecification(NotificationRecipientsBuilder.java:71)


com.glide.notification.cmn.NotificationRecipientsBuilder.build(NotificationRecipientsBuilder.java:42)


com.glide.notification.cmn.NotificationActionHandler.send(NotificationActionHandler.java:62)


com.glide.notification.cmn.NotificationActionHandler.process(NotificationActionHandler.java:51)


com.glide.policy.EventProcessor.processEvent(EventProcessor.java:73)


com.glide.policy.EventProcessor.process(EventProcessor.java:56)


com.glide.policy.EventManager.processEvents(EventManager.java:187)


com.glide.policy.EventManager.process(EventManager.java:129)


com.glide.script.GlideSystem.js_eventsProcess(GlideSystem.java:618)


inv146.invoke()


org.mozilla.javascript.FunctionObject.doInvoke(FunctionObject.java:565)


org.mozilla.javascript.FunctionObject.call(FunctionObject.java:480)


org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1196)


org.mozilla.javascript.gen.c1804.call(<refname>:1)


org.mozilla.javascript.gen.c1804.exec(<refname>)


com.glide.script.ScriptEvaluator.execute(ScriptEvaluator.java:163)


com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:64)


com.glide.script.ScriptEvaluator.evaluateStringWithPrefix(ScriptEvaluator.java:40)


com.glide.script.Evaluator.evaluatePossiblePrefixedString(Evaluator.java:231)


com.glide.job.RunScriptJob.evaluateScript(RunScriptJob.java:134)


com.glide.job.RunScriptJob.execute(RunScriptJob.java:79)


com.glide.schedule.JobExecutor.execute(JobExecutor.java:72)


com.glide.schedule.GlideScheduleWorker.executeJob(GlideScheduleWorker.java:163)


com.glide.schedule.GlideScheduleWorker.process(GlideScheduleWorker.java:128)


com.glide.schedule.GlideScheduleWorker.run(GlideScheduleWorker.java:58)


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