- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2023 02:08 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2023 05:11 AM
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();
}
mark the solution as correct and helpful if it solves your issue.
Regards,
Kalyan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2023 02:56 AM
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.
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2023 02:56 AM
Hello @Abhijeet Pawar ,
Please modify the incident property to 5 days. Please find the below screenshot
Thanks,
Omkar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2023 02:59 AM - edited ‎01-20-2023 03:01 AM
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 mark correct if my response has solved your query.
Cheers,
Mohammed Basheer Ahmed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2023 03:11 AM - edited ‎01-20-2023 03:12 AM
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