- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2019 10:52 PM
Hi,
I have a requirement to send 3 approval reminders each a week apart and the request should auto cancel after 3 reminders.
Here I have configured using scheduled job.
How can I send the remaining 2 reminders using the same scheduled job script.
var scApp = new GlideRecord('sysapproval_approver');
scApp.addEncodedQuery('state=requested^sysapproval.sys_class_name=sc_req_item^sys_created_onRELATIVELE@dayofweek@ago@7');
scApp.query();
while(scApp.next()){
gs.eventQueue('sc_reminder1',scApp,scApp.approver);
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2019 11:42 PM
while (scApp.next()){
if (scApp.sys_created_on <= gs.daysAgo(7)){
gs.eventQueue('sc_reminder1',scApp,scApp.approver);
}
else if (scApp.sys_created_on <= gs.daysAgo(14)){
gs.eventQueue('sc_reminder2',scApp,scApp.approver);
}
else if (scApp.sys_created_on <= gs.daysAgo(21)){
gs.eventQueue('sc_reminder3',scApp,scApp.approver);
var item = new GlideRecord('sc_req_item');
item.addQuery('sys_id',scApp.sysapproval);
item.addEncodedQuery('state!=numeric_value_for_cancel');
item.query();
if(item.next()){
item.state = numeric_value_for_cancel;
item.update();
}
//also update the state of approval record
scApp.state = 'cancelled';
scApp.update();
}
}
Regards
Air
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2019 02:08 AM
Great that you got it working with if. And thanks for sharing. That's how a small logic can make a difference. Will keep in mind while applying the logic in any future requirements. 🙂
Regards
Air

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2019 03:44 AM
I am assuming here, you had mention some time in your scheduled job ..
example 1 hr or 2 hr.
can you try now.
var scApp = new GlideRecord('sysapproval_approver');
scApp.addEncodedQuery('state=requested^sysapproval.sys_class_name=sc_req_item');
scApp.query();
while (scApp.next()){
if (scApp.sys_created_on <= gs.daysAgoStart(7)){
gs.log('Created on 1: '+scApp.sys_created_on+' Days Ago 1: '+gs.daysAgoStart(7));
gs.eventQueue('sc_reminder1',scApp,scApp.approver.toString());
}
else if (scApp.sys_created_on <= gs.daysAgoStart(14)){
gs.log('Created on 2: '+scApp.sys_created_on+' Days Ago 2: '+gs.daysAgoStart(14));
gs.eventQueue('sc_reminder2',scApp,scApp.approver.toString());
}
else if (scApp.sys_created_on <= gs.daysAgoStart(21)){
gs.log('Created on 3: '+scApp.sys_created_on+' Days Ago 3: '+gs.daysAgoStart(21));
gs.eventQueue('sc_reminder3',scApp,scApp.approver.toString());
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2019 04:06 AM
Hi Harsha,
Only reminder1 is triggering

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2019 04:26 AM
can you comment the eventQueue() , and see is it going inside other else if block .
if it's not going then add continue;
comment the eventQueue() function to validate the log.
var scApp = new GlideRecord('sysapproval_approver');
scApp.addEncodedQuery('state=requested^sysapproval.sys_class_name=sc_req_item');
scApp.query();
while (scApp.next()){
if (scApp.sys_created_on <= gs.daysAgoStart(7)){
gs.log('Created on 1: '+scApp.sys_created_on+' Days Ago 1: '+gs.daysAgoStart(7));
//gs.eventQueue('sc_reminder1',scApp,scApp.approver.toString());
}
else if (scApp.sys_created_on <= gs.daysAgoStart(14)){
gs.log('Created on 2: '+scApp.sys_created_on+' Days Ago 2: '+gs.daysAgoStart(14));
//gs.eventQueue('sc_reminder2',scApp,scApp.approver.toString());
}
else if (scApp.sys_created_on <= gs.daysAgoStart(21)){
gs.log('Created on 3: '+scApp.sys_created_on+' Days Ago 3: '+gs.daysAgoStart(21));
//gs.eventQueue('sc_reminder3',scApp,scApp.approver.toString());
}
}
if log is not coming from all the if else block then try with below script.
var scApp = new GlideRecord('sysapproval_approver');
scApp.addEncodedQuery('state=requested^sysapproval.sys_class_name=sc_req_item');
scApp.query();
while (scApp.next()){
if (scApp.sys_created_on <= gs.daysAgoStart(7)){
gs.log('Created on 1: '+scApp.sys_created_on+' Days Ago 1: '+gs.daysAgoStart(7));
gs.eventQueue('sc_reminder1',scApp,scApp.approver.toString());
continue;
}
else if (scApp.sys_created_on <= gs.daysAgoStart(14)){
gs.log('Created on 2: '+scApp.sys_created_on+' Days Ago 2: '+gs.daysAgoStart(14));
gs.eventQueue('sc_reminder2',scApp,scApp.approver.toString());
continue;
}
else if (scApp.sys_created_on <= gs.daysAgoStart(21)){
gs.log('Created on 3: '+scApp.sys_created_on+' Days Ago 3: '+gs.daysAgoStart(21));
gs.eventQueue('sc_reminder3',scApp,scApp.approver.toString());
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2019 04:29 AM
Hi Harsh & Air,
I replaced else if with if condition. It worked