incedent

mahesh009
Mega Guru

How can I set the state of an Incident to "Closed" automatically after a certain number of days?

6 ACCEPTED SOLUTIONS

Manikanta Kota
Mega Guru

Hi @mahesh009 ,

You can use Business rule or Schedule Job or Flow Designer for this.

 

Should my answer prove to be helpful, kindly mark it as such by clicking "Accept as Solution" and "Helpful."

Regards,

Manikanta. Kota

View solution in original post

Ramesh_143
Giga Guru

Hi @mahesh009 ,

To automatically set the state of an Incident to "Closed" in ServiceNow after a certain number of days, you can use either a **Scheduled Job** or a combination of a **Business Rule** and **Scheduled Script Execution**. A Scheduled Job can run daily, checking for incidents that have been resolved for a specific number of days (e.g., 7 days) and update their state to "Closed". Alternatively, a Business Rule can trigger upon incident resolution to set a closure date, and a scheduled script can then update incidents to "Closed" after the specified time has passed. Both approaches ensure incidents are closed automatically based on the defined criteria.

regards
Ramesh

View solution in original post

Anantha27
Mega Guru

Hi @mahesh009 
We can write a schedule item and business rule to close the incident after few days.
In the advanced tab you can write the script for autocloseincidents()
Using glide record hence you can close the incident.
Thank you

View solution in original post

Sai Krishna6147
Mega Guru

Hi @mahesh009 

we can use the schedule job and business rule to close the incident after few days.
in advanced tab you can write the script in schedule job

var gr = new GlideRecord('incident');
gr.addQuery('state', '!=', '6'); // Assuming '6' is the Closed state
gr.addQuery('sys_created_on', '<=', gs.daysAgo(30)); // Adjust the number of days
gr.query();
while (gr.next()) {
    gr.state = '6'; // Set to Closed
    gr.update();
}

Should my answer prove to be helpful, kindly mark it as such by clicking "Accept as Solution" and "Helpful."

Regards,

Venkata Sai Krishna

View solution in original post

VishaalRanS
Tera Guru

Hi @mahesh009 

 

To automatically close incidents in ServiceNow after a certain number of days, you can use one of two methods:

1. Scheduled Job: Runs daily to find incidents that have been resolved for a specific time (e.g., 7 days) and updates their status to "Closed."
2. Business Rule and Scheduled Script: A Business Rule sets a closure date when an incident is resolved, and a scheduled script closes those incidents after the specified period.

 

Both methods ensure incidents are closed automatically.

 

Thanks, and Regards

Vishaal

Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

Aditya02
Tera Guru

Hi @mahesh009 ,

 

You can achieve this via creating a Schedule job which is the best way to get your job done.

Refer these conversations to perform this..

 

https://www.servicenow.com/community/itsm-forum/how-to-auto-close-incidents-in-5-working-days-after-...

https://www.servicenow.com/community/itsm-forum/incident-autoclosure-in-5-business-days/m-p/447432

 

 

===================================***************=========================================

"If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!"

 

Thanks & Regards,

Aditya

=====================================***********==========================================

 

View solution in original post

8 REPLIES 8

VishaalRanS
Tera Guru

Hi @mahesh009 

 

To automatically close incidents in ServiceNow after a certain number of days, you can use one of two methods:

1. Scheduled Job: Runs daily to find incidents that have been resolved for a specific time (e.g., 7 days) and updates their status to "Closed."
2. Business Rule and Scheduled Script: A Business Rule sets a closure date when an incident is resolved, and a scheduled script closes those incidents after the specified period.

 

Both methods ensure incidents are closed automatically.

 

Thanks, and Regards

Vishaal

Please mark this response as correct or helpful if it assisted you with your question.

Aditya02
Tera Guru

Hi @mahesh009 ,

 

You can achieve this via creating a Schedule job which is the best way to get your job done.

Refer these conversations to perform this..

 

https://www.servicenow.com/community/itsm-forum/how-to-auto-close-incidents-in-5-working-days-after-...

https://www.servicenow.com/community/itsm-forum/incident-autoclosure-in-5-business-days/m-p/447432

 

 

===================================***************=========================================

"If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!"

 

Thanks & Regards,

Aditya

=====================================***********==========================================

 

Ramesh_143
Giga Guru

Hi @mahesh009 ,

There are several ways to automatically set the state of an Incident to "Closed" after a certain number of days in ServiceNow:

  1. Business Rule:
  • Create a new Business Rule on the incident table.
  • Set the "When to run" condition to "After Update".
  • In the script, check if the state field has changed to "Closed". If not, calculate the difference between the current date and the opened_at field. If the difference is greater than or equal to the desired number of days, set the state field to "Closed".
  1. Scheduled Job:
  • Create a new Scheduled Job.
  • Set the "Run type" to "Scheduled".
  • In the script, query for Incidents that are not closed and have been open for more than the desired number of days. Update the state field of these Incidents to "Closed".
  1. Workflow:
  • Create a new Workflow on the incident table.
  • Add a condition to check if the state field is not "Closed" and the difference between the current date and the opened_at field is greater than or equal to the desired number of days.
  • If the condition is met, add an action to set the state field to "Closed".

Example Business Rule Script:

Javascript&colon;- 

 

(function executeRule(current, previous /*null*/) {     // Check if the state has changed to "Closed"if (current.state == "Closed") {         return;     }     // Calculate the difference in daysvar daysOpen = gs.dateDiff(current.opened_at, gs.now(), 'days');     // Set the state to "Closed" if it's been open for more than 5 daysif (daysOpen >= 5) { current.state = "Closed"; } })(current, previous);

 Replace 5 with the desired number of days.

Thanks & Regards,

Ramesh

Please mark this response as correct or helpful if it assisted you with your question.

 

thullurishalini
Kilo Guru

Hi @mahesh009 

Sure! Here’s a summary:

To automatically set the state of an Incident to “Closed” after a certain number of days in ServiceNow:

  1. Create a Business Rule: Go to System Definition > Business Rules and create a new rule.
  2. Configure the Rule: Set the table to Incident, and enable advanced scripting.
  3. Set Conditions: Define conditions to run the rule when the state is Resolved and the incident hasn’t been updated for a specified number of days.
  4. Add Script: Use a script to check if the incident has been resolved for the specified number of days and then set its state to “Closed”.
  5. Save and Test: Save the rule and test it to ensure it works as expected.

This will ensure incidents are automatically closed after being in the “Resolved” state for the specified number of days.

Please mark this response as correct or helpful if it assisted you with your question.


thanks,

shalini.