Close incidents via email

Asosa
Tera Contributor

Hi folks!

I am trying to create a way to close incidents via email, without the need to open ServiceNow.

The main idea is that a user can send an email to the instance or to ServiceNow with the subject "Close incident XXXXX" and that this closes the incident without having to log in to the instance.

Any help is welcome, thank you very much!

1 ACCEPTED SOLUTION

Riya Verma
Kilo Sage
Kilo Sage

 Hi @Asosa ,

Hope you are doing great.

  1. Email Integration: a. Configure an inbound email action in ServiceNow, which will allow the system to receive and process incoming emails. b. Set up an email account or alias dedicated to receiving incident closure requests via email.

  2. Business Rule: a. Create a business rule that triggers when an email with the subject "Close incident XXXXX" is received. b. Extract the incident number (XXXXX) from the email subject using script logic. c. Use the incident number to locate and close the corresponding incident record.

(function executeRule(current, previous /*, gs*/) {
  var emailSubject = current.subject.toLowerCase();
  var closeKeyword = "close incident";

  if (emailSubject.startsWith(closeKeyword)) {
    var incidentNumber = emailSubject.replace(closeKeyword, "").trim();
    var incident = new GlideRecord('incident');
    
    if (incident.get('number', incidentNumber)) {
      incident.state = 7; // Set the incident state to 'Closed'
      incident.update();
    }
  }
})(current, previous);
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

View solution in original post

2 REPLIES 2

Riya Verma
Kilo Sage
Kilo Sage

 Hi @Asosa ,

Hope you are doing great.

  1. Email Integration: a. Configure an inbound email action in ServiceNow, which will allow the system to receive and process incoming emails. b. Set up an email account or alias dedicated to receiving incident closure requests via email.

  2. Business Rule: a. Create a business rule that triggers when an email with the subject "Close incident XXXXX" is received. b. Extract the incident number (XXXXX) from the email subject using script logic. c. Use the incident number to locate and close the corresponding incident record.

(function executeRule(current, previous /*, gs*/) {
  var emailSubject = current.subject.toLowerCase();
  var closeKeyword = "close incident";

  if (emailSubject.startsWith(closeKeyword)) {
    var incidentNumber = emailSubject.replace(closeKeyword, "").trim();
    var incident = new GlideRecord('incident');
    
    if (incident.get('number', incidentNumber)) {
      incident.state = 7; // Set the incident state to 'Closed'
      incident.update();
    }
  }
})(current, previous);
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

Thanks for the post. 

I'm just wondering how to configure the inbound action role to close this incident.

Do I have to make to make some adjustments in the role itself for make it work properly? 

All advices is appreciated here.Screenshot 2024-09-13 at 14.41.38.png