The CreatorCon Call for Content is officially open! Get started here.

after 5 days Auto close incident those are in resolved state

Abhijeet Pawar
Tera Contributor

Hello All,

I want to automatically close resolved incident after 5 days .how can I achieve this functionality can anyone please guide me on this?

Thank You.

1 ACCEPTED SOLUTION

Hi @Abhijeet Pawar ,

from navigation select scheduled job > click new> select "Automatically run a script of your choosing"
and write the code which you want to check and also remove gr.initilaize() from your code then save and click on Execute now 

for your reference below is the code 

var gr = new GlideRecord("incident");
gr.addQuery('state','6');
gr.query();
while(gr.next()){

gr.state = 7;
gr.close_code = 'Solution provided';
gr.close_notes = 'hello';
gr.active = false;
gs.log("Incident has closed");
gr.update();

}Screenshot 2023-01-20 at 6.40.04 PM.png




mark the solution as correct and helpful if it solves your issue.

 

Regards,

Kalyan

View solution in original post

11 REPLIES 11

Neeraj Modi
Tera Guru

Hi @Abhijeet Pawar 

 

You can auto close the incident using the "incident properties"

From left navigation >Incident > Administration > Incident properties

 

Update the days in Number of days field to 5, it will work.

 

NeerajModi_0-1674212082501.png

 

Please mark the suggestion as helpful, if you find it useful to you or others who wants to refer similar content.
Please mark the solution as correct, if the answer provided by me has resolved your query.


Thank you!

 

Omkar Kumbhar
Mega Sage

Hello @Abhijeet Pawar ,

Please modify the incident property to 5 days. Please find the below screenshot

OmkarKumbhar_0-1674212145347.png

Thanks,

Omkar

If I was able to help you with your case, please click the Thumb Icon and mark as Correct.

Basheer
Mega Sage

Hi @Abhijeet Pawar ,

Create a scheduled job and use below code. this code includes business off days as well.

 

updateRecords();
function updateRecords(){
var inc = new GlideRecord('incident');
inc.addQuery('state', 6);
inc.query();
while(inc.next()){
var start = new GlideDateTime(inc.sys_created_on);
var nowTime = new GlideDateTime();
var days = getDateDiff(start,nowTime);
if(days >=5){
inc.state = 7;
inc.incident_state = 7;
inc.active = false;
inc.update();
}
}
}
}

function getDateDiff(start , end){
        var days = 0;
        while (start < end) {
            start.addDaysUTC(1);
            if (start.getDayOfWeekUTC() != 6 && start.getDayOfWeekUTC() != 7){
                days++ ;
            }
        }
        return days;
    }

 

 

 

Please hit like button if my suggestion has helped you in any way.
Please mark correct if my response has solved your query.

Cheers,
Mohammed Basheer Ahmed.

kalyan13
Tera Guru

Hi @Abhijeet Pawar ,

 

1: You can do by changing the incident property  as @Omkar Kumbhar  and @Neeraj Modi  shown
2: You can also create a scheduled job which will run daily and updates the records. Below is the code for the same

var gr = new GlideRecord("incident");
gr.addQuery('state','6');
gr.addQuery('sys_updated_on','>',gs.daysAgo(5));

gr.query();

var total = gr.getRowCount();
gs.log('total row : ' +total);
while(gr.next()){

gr.state = 7;
gs.log("Incident has closed");
gr.update();

}

prefer according to your requirement. My suggestion is better to  create a scheduled job.

If my solution helps you. Please mark as helpful and correct.

 

Regards,

Kalyan