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

catalog task

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();
}



 

Best Regards
Aman Kumar

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();
}

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();
}

Best Regards
Aman Kumar

Kartik Sethi
Tera Guru
Tera Guru

Hi @Shweta Kasbe 

 

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