Send Approver notification if created more then 3 days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2016 08:03 AM
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:
- 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:
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'.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2016 03:30 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2018 01:06 AM
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:
- var queryString = 'sys_created_on<javascript:gs.daysAgoStart(0)^state=requested';
- var au = new ArrayUtil();
- var answer = [];
- var app = new GlideRecord('sysapproval_approver');
- app.addEncodedQuery(queryString);
- app.query();
- while(app.next()){
- if (!au.contains(answer, app.approver.sys_id)) {
- answer.push(app.approver.sys_id);
- }
- }
- 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:
- You have outstanding approvals awaiting response. Please click the link below to access a list of your approvals.
- <mail_script>
- var baseURL = "https://"+gs.getProperty('instance_name') + ".service-now.com/";
- var appr = 'sysapproval_approver_list.do?sysparm_query=approver%3Djavascript%3AgetMyApprovals()'
- template.print('<a href='+baseURL+appr+'> My approvals</a>');
- </mail_script>
https://community.servicenow.com/thread/160029
Thanks
Sandeep