Resolve Incident to closed

Avinash Dubey2
Tera Contributor

I want to Write a script to close all resolved incidents which are not updated on last 3 days

I have hardcoded the last the days but i want it to be calculated.

var str ="state=6^sys_updated_on<=javascript:gs.dateGenerate('2022-08-09','23:59:59')";

var gr = new GlideRecord('incident');

gr.addEncodedQuery(str);

gr.query();

while(gr.next()){

 gr.setValue('state','closed');

 gs.print(gr.state);

}

1 ACCEPTED SOLUTION

@Avinash Dubey 

Is your issue resolved?


Feel free to mark correct, if your issue has been resolved, so it ends up in solved queue.

Will be helpful for others looking for the similar query.

Best Regards
Aman Kumar

View solution in original post

10 REPLIES 10

Aman Kumar S
Kilo Patron

Hi @Avinash Dubey 

Use below encoded Query:

state=6^sys_updated_onRELATIVELT@dayofweek@ago@3

Best Regards
Aman Kumar

Hi After updating the query :

//state=6^sys_updated_onRELATIVELT@dayofweek@ago@3
var str ="state=6^sys_updated_onRELATIVELT@dayofweek@ago@3"; //don’t use date ,calculate dynamically
var gr = new GlideRecord('incident');
gr.addEncodedQuery(str);
gr.query();
while(gr.next()){
 gr.setValue('state','7');  //update the 

 gs.print(gr.state);
gr.update();
}

i am not getting any result 

Are you sure, you have incidents last updated 3 days ago in resolved state?

Best Regards
Aman Kumar

@Avinash Dubey 

Is your issue resolved?


Feel free to mark correct, if your issue has been resolved, so it ends up in solved queue.

Will be helpful for others looking for the similar query.

Best Regards
Aman Kumar