Need to Auto close the ticket from resolved to closed after 7 days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2022 11:03 PM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2022 11:21 PM
catalog task

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2022 11:37 PM
Check if your scheduled job is running everyday:
var daysToCLose = 7;
var gr = new GlideRecord('sc_task');
gr.addQuery('state', '8');
gr.addQuery('sys_updated_on', '<', gs.daysAgoStart(daysToCLose));// no of days
gr.query();
while (gr.next()) {
gr.state = '3';
gr.work_notes = 'Task automatically closed after ' + daysToCLose + ' days in the Resolved state.';
gr.active = false;
gr.update();
}
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2022 12:09 AM
I need to testing i m trying for first 10 mins but this is not working
var daysToCLose ='state=8^sys_updated_onRELATIVELT@minute@ago@10';
var gr = new GlideRecord('sc_task');
gr.addQuery('state', '8');
gr.addQuery('sys_updated_on', '<', gs.daysAgoStart(daysToCLose));// no of days
gr.query();
while (gr.next()) {
gr.state = '3';
gr.work_notes = 'Task automatically closed after ' + daysToCLose + ' days in the Resolved state.';
gr.active = false;
gr.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2022 03:17 AM
Can you check logs?
try putting gs.info statements in line
while (gr.next()) {
gs.info("test num = "+ gr.number);// after running your sch job check in script logs
gr.state = '3';
gr.work_notes = 'Task automatically closed after ' + daysToCLose + ' days in the Resolved state.';
gr.active = false;
gr.update();
}
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2022 11:35 PM
Hi
The code looks good. Could you please share the screenshot of the Scheduled Job. And did you try to execute the Scheduled Job?
Thanks and regards,
Kartik