The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Auto Close Service Request after 7 days

SN Rookie
Giga Expert

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?

1 ACCEPTED SOLUTION

Chalan B L
Giga Guru

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

 

find_real_file.png

 

Mark the answer as correct and helpful if it helped you..!!

 

Regards,

Chalan

View solution in original post

6 REPLIES 6

Chalan B L
Giga Guru

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

 

find_real_file.png

 

Mark the answer as correct and helpful if it helped you..!!

 

Regards,

Chalan

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

find_real_file.png

find_real_file.pngfind_real_file.png

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:-

 

Ct111
Tera Sage

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.