How to auto close the completed RITM after 5 business days.

VIKAS MISHRA
Tera Contributor

Below is the Scheduled job that i have written to auto closed the Completed RITM after 7 days. but as per the requirement it should auto close the RITM after 5 business days only excluding sat sun and holidays , is it possible ?

var gr = new GlideRecord("sc_req_item");
gr.addEncodedQuery("active=true^state=16^u_completed_onRELATIVELT@dayofweek@ago@7");
gr.query();
while (gr.next()) {
    var requestedfor = gr.requested_for;
    gr.state = '3';
    gr.close_code = "Solved (Permanently)";
    gr.close_notes = "Closing resolved ticket";
	gs.eventQueue('Auto-Closure Requested item', gr, requestedfor);
    gr.update();	
}
4 REPLIES 4

Anurag Tripathi
Mega Patron
Mega Patron

It is doable and you will need to create a schedule (or use any existing) . Check this out,

How to close ticket after 3 business days - ServiceNow Community

-Anurag

Hi @VIKAS MISHRA 

On your above script, main change should be "@business_time" keyword, instead of "@dayofweek". This keyword will ensure that only business days are counted, which excludes weekends and holidays. Also, you need to make sure, your instance has configured business hours and holidays. If you do, ensure to use right keyword as mentioned.

Please let me know if you have additional query.


Thanks,
Vamshi

Can you please provide me with exact query what i need to put

Hi @VIKAS MISHRA 

Just apply and change your query on above code, something like this.

gr.addEncodedQuery("active=true^state=16^u_completed_onRELATIVELT@business_time@5");

And ensure you check if your instance is configured business hours and holidays.

Please mark helpful/correct, if your query is addressed and/or answered!

Thanks,
Vamshi