Auto-Close Incidents after Resolving

saireddy389
Kilo Contributor

Hi Guys,

My scenario is

Description :

As a user, I want to make sure old resolved Incidents are closed in a timely manner (7 days) so the teams can focus on active issues.

7 days - all priority except 0 and 1

Priority 2 to 5 Incidents are auto closed 7 days after Resolved.

I did as shown below

when to run :

when : After     Order : 100

In Filter condition: I took   Priority   is one of     2-High

                                                                                                                                                3-Moderate

                                                                                                                                                4-Low

                                                                                                                                                5- Planning

state is Resolved

In Actions:

State to close

Script :

// This script automatically closes incidents that are resolved

// and haven't been updated in the specified number of days.

// This number is a property in System Properties.

// To place a comment in the incident, uncomment the "gr.comments" line.

autoCloseIncidents();

function autoCloseIncidents() {

var ps = gs.getProperty('glide.ui.autoclose.time');

var pn = parseInt(ps);

var queryTime = new GlideDateTime();

queryTime.addDaysUTC(-pn);

if (pn > 0) {

var gr = new GlideRecord('incident');

gr.addQuery('incident_state', IncidentState.RESOLVED);

gr.addQuery('sys_updated_on', '<', queryTime);

gr.query();

while(gr.next()) {

gr.incident_state = IncidentState.CLOSED;

//   gr.comments = 'Incident automatically closed after ' + pn + ' days in the Resolved state.';

gr.active = false;

gr.closed_by = gr.resolved_by;

gr.update();

}

}

}

Can any body suggest me what i did wrong and what needs to change in this

Thanks

Sai,

3 REPLIES 3

Mihir Mohanta
Kilo Sage

You have to set auto close property or write scheduled job.


Business rule is not required in this case.



Please go through the below link



Configure incidents to close automatically


HarshTimes
Tera Guru

Hi Sai


Use below script it will work




var query = "state=6^priorityIN2,3,4,5^opened_at<javascript:gs.beginningOfLast7Days()" ;


var gr = new GlideRecord('incident');


gr.addEncodedQuery(query);


gr.query();


while(gr.next()) {


gr.incident_state = 7 ;// PUT THE STATE VALUE OF CLOSED HERE


//   gr.comments = 'Incident automatically closed after ' + pn + ' days in the Resolved state.';


gr.active = false;


gr.closed_by = gr.resolved_by;


gr.update();


}


Chuck Tomasi
Tera Patron

Hi Sai,



I invite you to take a look at a scriptless solution I built on to OOB scheduled jobs that can help you with this. It was built for use cases just like this.



Scriptless scheduled jobs