- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 11:39 PM
Hi All,
We have a custom table (u_service_request). We want all the service requests which are in Resolved state to auto-close in 7 days similar to how it happens in Incidents. How can we achieve that?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 11:44 PM
Hello User,
Write a Schedule job for this requirement which runs every day
var query = 'state=-4^sys_updated_onRELATIVELT@dayofweek@ago@7'; //state is resolved
var gr = new GlideRecord('table_name');
gr.addEncodedQuery(query);
gr.query();
while(gr.next()){
gr.state = '3'; //set the state to closed
gr.update();
}
Mark the answer as correct and helpful if it helped you..!!
Regards,
Chalan

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 11:44 PM
Hello User,
Write a Schedule job for this requirement which runs every day
var query = 'state=-4^sys_updated_onRELATIVELT@dayofweek@ago@7'; //state is resolved
var gr = new GlideRecord('table_name');
gr.addEncodedQuery(query);
gr.query();
while(gr.next()){
gr.state = '3'; //set the state to closed
gr.update();
}
Mark the answer as correct and helpful if it helped you..!!
Regards,
Chalan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2022 10:15 PM
Hi Chakan,
I have a custom table (u_sap) I want if state is resolved Then ticket should be auto closed after 1 day. please let me know how to do it.
Thanks & Regards
Keval

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2022 01:44 AM
Hii @keval,
try this tested code and change the value as per your requirement like incident to u_sap, change the Time zone in scheduled jobs, give hour means timing in which this scheduled job run.
Copy and paste the code:-
var gr = new GlideRecord("incident");//change table name as u_sap
gr.addEncodedQuery("active=true^state=6^resolved_atONYesterday@javascript:gs.beginningOfYesterday()@javascript:gs.endOfYesterday()");// paste copy query in string format
gr.query();
while(gr.next()){
gr.state = '7';// change the choice value of closed
gr.close_code ="Solved (Permanently)";
gr.close_notes = "Closing resolved ticket";
gr.update();
}
Regards,
Imran Ahmad.
Please Mark Helpful below:-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 11:45 PM
There is business rule in Incident with name incident autoclose
you can refer if it , in the same way you need to code just replace the incident table with your table.
Mark my ANSWER as CORRECT and HELPFUL if it helped.