Send Approver notification if created more then 3 days

germc
Giga Expert

Hi guys,

We are doing some work around sending approval notification reminders and we have a solution implemented whereby they are sent out every 3 days.

However, we want to also add a condition that reminder is not sent unless the approval is more than 3 days old. Is this possible?

So this is where we are at so far:

  • Created new event:

find_real_file.png

  • Created notification to send when even is fired.
  • Created a schedule o run periodically every 3 days with the following script:

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("approval.reminder",gr, gs.getUserID(), gs.userName());

      }  

This is how the schedule looks:

find_real_file.png

Has anyone achieved it so that reminder is not sent unless the approval is more than 3 days old? Field is called 'sys_created_on'.

6 REPLIES 6

danny_ply
Kilo Explorer

You could create a scheduled job tied to each approval (via Business rule for example)



The scheduled job would be scheduled to execute in 3 days, it could contain a script to generate an event. After 3 days the event is created, you could create a script action to run on that event and have a condition to generate another event to trigger a notification ONLY if the approval is still pending. The script action could also re-generate a new scheduled job for the next 3 days to repeat the process in case a reminder was needed



Sandeep Kumar6
Giga Guru

Hi germc,



I know I'm late in the game here, but wanted to share this modification of the code in case anyone else wants to try it. I took out the for loop at the end, and this adds all of the approvers for one event in Parm 1



Scheduled job:





  1. var queryString = 'sys_created_on<javascript:gs.daysAgoStart(0)^state=requested';  
  2. var au = new ArrayUtil();  
  3. var answer = [];  
  4. var app = new GlideRecord('sysapproval_approver');  
  5. app.addEncodedQuery(queryString);  
  6. app.query();  
  7. while(app.next()){  
  8.   if (!au.contains(answer, app.approver.sys_id)) {  
  9.   answer.push(app.approver.sys_id);  
  10.   }  
  11. }  
  12. gs.eventQueue('approvals_pending', app, answer);  


The email notification looks like this:Send when: Event is fired


Event name: approvals_pendingEvent parm 1 contains recipient: true


Subject: Approval reminderBody:




  1. You have outstanding approvals awaiting response. Please click the link below to access a list of your approvals.  
  2.  
  3.  
  4. <mail_script>  
  5. var baseURL = "https://"+gs.getProperty('instance_name') + ".service-now.com/";  
  6. var appr = 'sysapproval_approver_list.do?sysparm_query=approver%3Djavascript%3AgetMyApprovals()'  
  7.  
  8.  
  9. template.print('<a href='+baseURL+appr+'> My approvals</a>');  
  10.  
  11.  
  12. </mail_script>  



https://community.servicenow.com/thread/160029




Thanks


Sandeep