Help with Script - Trigger approval reminder email in every 3 Business days till 30 Buisness Days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2024 06:17 AM
Dear Team,
I have a requirement to trigger an approval reminder email to approver in every 3 Business days and continue to trigger till 30 Business Days if no approver not approves the respective RITM, if RITM not approved/rejected till 30th day, then RITM will be cancelled.
I have wrote the below Scheduled Job script, but it triggers reminder emails in every business days
notifyApprover();
function notifyApprover() {
var notifydays = ['3', '6', '9', '12', '15', '18', '21', '24', '27'];
var apprv = new GlideRecord('sysapproval_approver');
apprv.addEncodedQuery('sysapproval.ref_sc_req_item.cat_item=ba2d4df71b77fd5063b0a60bbc4bcbaa^ORsysapproval.ref_sc_req_item.cat_item=f4e78c311b0c46d063b0a60bbc4bcb1d^state=requested');
apprv.query();
while (apprv.next()) {
var createdDateinit = apprv.sysapproval.sys_created_on.toString();
var createdDateinitarr = createdDateinit.split(' ');
var createdfinal = createdDateinitarr[0] + " 00:00:00";
var currentDate = String(new GlideDateTime());
var currentDatearr = currentDate.split(' ');
var currentDatefinal = currentDatearr[0] + " 00:00:00";
var schid = '28a5b8ff1b1e641081f8dd77cc4bcb07';
var plannedTaskAPI = new SNC.PlannedTaskAPI();
var resp = plannedTaskAPI.calculateDuration(createdfinal, currentDatefinal, schid);
var response = new JSON().decode(resp);
var duration = response.duration;
var durationdays = duration.split(' ')[0];
var ritmObj = apprv.sysapproval.getRefRecord();
if (notifydays.indexOf(durationdays) > -1) {
gs.eventQueue('approval.notify.consultant', ritmObj, apprv.getValue('approver'), apprv.getDisplayValue('approver'));
}
if (durationdays == '30') {
cancelRequest(apprv.sysapproval.toString());
}
}
}
function cancelRequest(ritmid) {
var ritmObj = new GlideRecord('sc_req_item');
if (ritmObj(ritmid)) {
ritmObj.state = 1000;
ritmObj.update();
}
}
O/p of Emails
Kindly help to modify the above script so that it can trigger in every 3 business days not every business days
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2024 01:42 AM
Hi,
So the issue is to get logic in place to make sure the trigger only happens on every third day.
This piece might help finding dates that match.
var today = new GlideDateTime();
var anotherDay = new GlideDateTime('2024-08-01'); // just an example date..
var arrayCheckpoints = [3,6,9,12,15,18,21,24,27]; // your checkpoints
for (var i=0; i<arrayCheckpoints.length; i++){
anotherDay.addDays(3); // add three more days with each iteration in your array
//gs.info('New date another day: ' + anotherDay.getValue());
// check if the added days match the other date with todays date
if (anotherDay.getDate().toString() == today.getDate().toString()){
gs.info('Match found for day checkpoint: ' + arrayCheckpoints[i]);
// insert logic here that should happen when the dates match
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2024 01:49 AM
Sir @OlaN I have tried every possible way with the modification as per my understanding may be I am getting things wrong
Humble request you to please share the final script so that it will work.
I need only this help