Need to Auto close the ticket from resolved to closed after 7 days

Shweta Kasbe1
Tera Contributor

Need to Auto close the ticket from resolved to closed after 7 days.I have written a scheduled job script but its not working. Pls help me in this.

var query = 'state=8^sys_updated_onRELATIVELT@dayofweek@ago@7'; //state is resolved
var gr = new GlideRecord('sc_task');
gr.addEncodedQuery(query);
gr.query();while(gr.next()){
gr.state = '3'; //set the state to closed
gr.update();
}

10 REPLIES 10

Sagar Pagar
Tera Patron

Hi Shewta,

Please check this article: How to Auto Close ‘Resolved’ Incidents after 7 days in Service Now

old thread: How to Auto close incidents in 5 working days, after incident state is resolved.

 

Thanks!

Sagar Pagar

The world works with ServiceNow

Kartik Sethi
Tera Guru
Tera Guru

Hi @Shweta Kasbe,

 

You can take reference of OOTB Business Rule:

Link: https://<your_instance_name_here>.service-now.com/sys_script.do?sys_id=d67b8d9ec0a80118008cd8f0f7f92fae

 

This Business Rule is for autoclosing the Incidents after certain days (days are provided in the System Properties which you can find in the Business Rule itself ). So you can make a copy of this Business Rule and adjust it as per your requirements. 

Please mark my answer as correct if this solves your issues!

If it helped you in any way then please mark helpful!

 

Thanks and regards,

Kartik

Hi @shweta Kasbe 

Is your issue resolved or are you still facing it?

 

Please mark my answer as correct if my previous reply solves your issues!

If it helped you in any way then please mark helpful!

 

Thanks and regards,

Kartik

Aman Kumar S
Kilo Patron

Hey,

Your code looks fine except for if you want to close a ticket, why are you querying "sc_task"?

Can you clarify if you are trying to close a catalog task or incident?

If incident, you need to add incident in the gliderecord

Best Regards
Aman Kumar