How to Auto Close/reject after 7 business days of an approval in workflow

shivani39
Tera Expert

 

Hi All,

How do we Auto Close/reject an approvla after 7 business days in a Workflow.

Appreciate your help!

Thanks

Shivani

 

 

 

 

 

 

 

 

 

 

3 REPLIES 3

Baala T
Mega Guru

Hi,

Are we planning to do this for specific Workflow or globally to all the requests.

If it is globally for all the approval request, then will implement the Scheduled Job with date filter criteria to move the request to Cancelled. In the workflow we should have different flow for Cancelled.

If it is specific for a workflow, will use the DueDate field in Approval table, will keep updated with 7 days duration. In the workflow Branch to Approval and Timer activity. When the Due Date exceeds with current time, system move it to next stage.

 

Regards,
Baala T

Michael Knight
Kilo Contributor

I am also looking to Auto-Reject a RITM if it has not been approved after 7 days.  Could you suggest script for Scheduled Job?

Michael Knight
Kilo Contributor

gs.log("Job run::aged approval Rejected:" + new GlideDateTime());

var gr = new GlideRecord('sysapproval_approver');
gr.addEncodedQuery('state=requested^sysapproval.numberSTARTSWITHRITM');
gr.query();
while (gr.next()) {

var gdStart = new GlideDateTime(gr.sys_created_on);
var g1 = new GlideDateTime();

var date_diff = GlideDateTime.subtract(gdStart, g1);
var nDays = parseInt(date_diff.getNumericValue()/86400000);
gs.info('Approval for->' + gr.sysapproval.number + ' ' + nDays);
if (nDays > 7) {
gs.eventQueue('Approval.reminder', gr);
gr.state = 'rejected';

gr.setWorkflow(false);
gr.update();
}
}

gs.log("Job complete::aged approval Rejected:" + new GlideDateTime());

 

Would this do the requirement?