- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2018 03:29 AM
Hi,
I am using this code to send reminders to Managers where approval has been pending for more than 7 days. It has been created to run as a daily scheduled job.
The script does run OK and sends out the chase email. However I have noticed that it sends the chase every day after the request is 7 days or more old. This would mean if someone is on leave they may get multiple emails for the same approval. IE if the request is raised 6 days before they go on leave and they do not approve, then they are off for 2 weeks, they may get over 10 emails for the same request.
Is it possible to add something into the script that updates the request to show the chase has been sent? So it then waits another 7 days before sending the chase email again?
var ritm = new GlideRecord('sc_req_item');
var encQuery = 'active=true^state=1'; //1 is state pending approval;
ritm.addEncodedQuery(encQuery);
ritm.query();
while (ritm.next()) {
var chkApprvl = new GlideRecord('sysapproval_approver');
chkApprvl.addQuery('document_id', ritm.sys_id);//find the approval related to this item
chkApprvl.addQuery('state', 'requested');//its state should be requested
chkApprvl.addQuery('sysapproval.sys_class_name','sc_req_item');
chkApprvl.addQuery('sys_updated_onRELATIVELE@dayofweek@ago@7'); //this checks if the approval has not be updated for 7 days
chkApprvl.query();
while(chkApprvl.next()) {
gs.eventQueue('sc_req_item.approval.overdue', chkApprvl, chkApprvl.approver, chkApprvl.approver.getUserName()); //this will create the event
ritm.work_notes = 'Reminder email to approver sent after 7 days.';
ritm.update();
}
}
Solved! Go to Solution.
- Labels:
-
Field Service Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2018 07:12 AM
Did you try using daysAgo() method
Ex: replace daysAgoStart with daysAgo(number of day)
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('state', 'requested');
gr.addQuery('sys_updated_on', '<', gs.daysAgoStart(5));
gr.query();
https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=r_GS-daysAgo_N
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2018 06:58 AM
I have been told to keep it simple and have three jobs that run daily - for approvals pending by 7, 14 and 21 days.
Please can some one recommend what is the keyword to look at exact 7 days difference?
The one I have using (below) returns <= 7, I need =7
chkApprvl.addQuery('sys_updated_onRELATIVELE@dayofweek@ago@7');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2018 07:12 AM
Did you try using daysAgo() method
Ex: replace daysAgoStart with daysAgo(number of day)
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('state', 'requested');
gr.addQuery('sys_updated_on', '<', gs.daysAgoStart(5));
gr.query();
https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=r_GS-daysAgo_N
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2020 10:04 AM
Hi TK,
i am also facing same issue could pls give me answer above one