- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2015 07:02 AM
We have written a scheduled job that sends an 'Approval Pending' reminder to approvers every 3 days. We would like to eventually cancel the approvals due to no response and close the parent record while notifying the requester.
Initially it seams like setting the <sysapproval_approver.state> field to 'Cancelled' was the right move but this seems to have no affect on the parent record (sc_request or sc_req_item). So my options are either to write all the necessary business rules/ script includes to cancell the parent record when the approval is cancelled or to set <sysapproval_approver.state> field to 'Rejected'.
Has any one else encountered this? I am trying to determine the bast way to handle this.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2015 07:08 AM
It would probably be a little easier just to reject the approval and have it kick off all the automation through the workflow. You could have it add a note to the approval as well that it was auto-rejected or something like that.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2015 07:08 AM
It would probably be a little easier just to reject the approval and have it kick off all the automation through the workflow. You could have it add a note to the approval as well that it was auto-rejected or something like that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2015 07:20 AM
Josh, we do exactly this, but instead of canceling the approval, we auto-reject it.
Here is the Script Include that I use, which is called from a Scheduled Job.
There are two fields we added to the sysapproval_approver table: u_num_of_reminders and u_reminder_date, that are used to determine the last reminder sent, and the total number of reminders sent. Once you hit 3 reminders, the approval is rejected. It can obviously be tuned to your business practice.
var ReqApprovalReminder = Class.create();
ReqApprovalReminder.prototype = {
initialize: function() {
},
RequestApproReminder : function(){
var appr = new GlideRecord('sysapproval_approver');
appr.addQuery('state','requested');
appr.addEncodedQuery('sys_created_onRELATIVELE@hour@ago@24');
appr.query();
var noOfdays = 0;
while(appr.next()){
if(appr.u_reminder_date!= ""){
var dateDiff = gs.dateDiff(appr.u_reminder_date.getDisplayValue(),gs.nowDateTime(),false);
noOfdays = dateDiff.split(" ")[0];
}
if((appr.u_num_of_reminders == "") || (appr.u_num_of_reminders == 0)) {
//gs.eventQueue("reminder.emails", appr, gs.getUserID(), gs.getUserName());
// If you want to some specific order guide uncomment if
//if(appr.sysapproval.u_order_guide == 'OrderGuid_Sys_is'){
gs.eventQueue("approval.reminders", appr, appr.approver.sys_id, appr.approver.name);
appr.u_num_of_reminders += 1; // 1st Reminder sent
appr.u_reminder_date = gs.nowDateTime();
//}
} else if ((appr.u_num_of_reminders == 1) && (noOfdays > 2)) {
//if(appr.sysapproval.u_order_guide == 'OrderGuid_Sys_is'){
gs.eventQueue("approval.reminders", appr, appr.approver.sys_id, appr.approver.name);
appr.u_num_of_reminders += 1;// 2nd Reminder sent
appr.u_reminder_date = gs.nowDateTime();
//}
} else if ((appr.u_num_of_reminders == 2) && (noOfdays > 10)) {
//if(appr.sysapproval.u_order_guide == 'OrderGuid_Sys_is'){
gs.eventQueue("approval.cancelled", appr, appr.approver.sys_id, appr.approver.name);
appr.state = 'rejected'; // Now Request Cancelled
appr.comments = 'Approval automatically rejected by system due to time expiration';
appr.u_num_of_reminders += 1;
appr.u_reminder_date = gs.nowDateTime();
//var reqNum = appr.sysapproval.number;
//this._cancellRequest(reqNum);
//}
}
appr.update();
}
},
_cancellRequest: function(reqNum){
var scReq = new GlideRecord("sc_request");
scReq.addQuery('number',reqNum);
scReq.query();
if(scReq.next()){
scReq.state = 4;
scReq.stage = 'closed_incomplete';
scReq.request_state = 'closed_cancelled';
scReq.update();
}
}};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2015 11:30 AM
Thie is close to what I am trying to do. Does cancelling the request in this manner leave the approval record and Requested items open?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2015 11:43 AM
That's what _cancelrequest will do, but I didn't implement it, because our workflow automatically cancels the requests whenever the approval is rejected, so we rely on the Workflow to handle those issues, not the Script Include.
-Rob