Schedule job to close Incidents

sanathk
Tera Expert

Hello Community,

 

I have a requirement; I need to auto close the incidents which are not updated in last 30 days through schedule job which should run every day. can someone please help me with the code for this?

 

Thanks & regards,

Sanath K

2 ACCEPTED SOLUTIONS

Hi @sanathk 

 

I don't think this filter is possible in Flow Designer. You need to write a scheduled job. Sharing the outline of the code-

 

(function() {
  
    var gr = new GlideRecord('incident');
    gr.addQuery('sys_updated_on', '<', gs.daysAgoStart(30)); 
    gr.addQuery('cmdb_ci.name', 'NOT LIKE', 'ABC%'); 
    gr.addQuery('active', true); 
    gr.query();

    while (gr.next()) {
            gr.setValue('state', 7); 
            gr.update();
    }
})();

 

Please mark my answer helpful and correct.

 

Regards,

Amit

View solution in original post

Hi @Amit Pandey ,Thankyou so much for your support the above mentioned code will work and also we can do like this also.

var gr = new GlideRecord("incident");

gr.addEncodedQuery("encoded query with relevant conditions like updated on past 30 days");

gr.query();

while (gr.next()) {

       if(!gr.cmdb_ci,name.startsWith("ABC",0){

            gr.state = '7';

           gr.update();

   }

}

 

View solution in original post

11 REPLIES 11

Hi @sanathk 

 

I don't think this filter is possible in Flow Designer. You need to write a scheduled job. Sharing the outline of the code-

 

(function() {
  
    var gr = new GlideRecord('incident');
    gr.addQuery('sys_updated_on', '<', gs.daysAgoStart(30)); 
    gr.addQuery('cmdb_ci.name', 'NOT LIKE', 'ABC%'); 
    gr.addQuery('active', true); 
    gr.query();

    while (gr.next()) {
            gr.setValue('state', 7); 
            gr.update();
    }
})();

 

Please mark my answer helpful and correct.

 

Regards,

Amit

Hi @Amit Pandey ,Thankyou so much for your support the above mentioned code will work and also we can do like this also.

var gr = new GlideRecord("incident");

gr.addEncodedQuery("encoded query with relevant conditions like updated on past 30 days");

gr.query();

while (gr.next()) {

       if(!gr.cmdb_ci,name.startsWith("ABC",0){

            gr.state = '7';

           gr.update();

   }

}