How to prevent Incidents created from Alerts getting auto-close without mandatory fields?

Hritik
Tera Expert

Hello Community,

 

Please consider a following scenario:

 

We have a configuration in Alert management that we can create incident from Alert when clicked on UI Action "Create Incident" from Alert. After when that particular alert is closed, the Incident associated to it also gets closed automatically, leaving all the mandatory fields as unfilled.

 

Since, this auto-closure is executed by system, no data policy prevents the incidents that are unfilled with mandatory details from auto-closure. 

We want to restrict this process from executing as there are already thousands of Alerts that are closed but not filled with mandatory details.

 

Kindly guide me with best possible options to tackle this.

1. Either we can stop the Incidents from auto close even if Alert associated to it is closed. (If possible, then how?)

2. Any other suitable solution.

 

Thanks in Advance,

Hritik.

 

3 REPLIES 3

Ratnakar7
Mega Sage
Mega Sage

Hi @Hritik ,

 

You can try the following solutions:

  1. Option to stop Incidents from auto-close:

You can create a business rule that runs when an incident is about to be auto-closed. The business rule can check if all mandatory fields are filled, and if not, it can prevent the incident from being closed and send a notification to the assigned user or group to fill the mandatory fields. Here is an example script that you can modify and use in your business rule:

 

(function executeRule(current, previous /*null when async*/) {
  var mandatoryFields = ['short_description', 'description', 'impact', 'urgency', 'priority']; // list of mandatory fields
  var isMandatoryFieldsFilled = true;
  mandatoryFields.forEach(function(field) {
    if (!current[field].value) {
      isMandatoryFieldsFilled = false;
      gs.addInfoMessage("Please fill the mandatory field " + field);
    }
  });
  if (!isMandatoryFieldsFilled) {
    current.setAbortAction(true); // prevent incident from auto-closing
    gs.eventQueue("incident.mandatory_fields_missing", current, current.assignment_group); // send notification to the assigned group
  }
})(current, previous);

 

   

    2. Other suitable solution:

You can modify the Alert management configuration to prevent the creation of incidents if mandatory fields are not filled. You can add a data policy that runs when a new incident is created from an alert, and checks if all mandatory fields are filled. If not, the data policy can prevent the incident creation and send a notification to the user who tried to create the incident. Here is an example data policy that you can modify and use:

 

Table: Incident
When: Before
Insert: true
Condition: current.source == 'Alert'
Script:

var mandatoryFields = ['short_description', 'description', 'impact', 'urgency', 'priority']; // list of mandatory fields
var isMandatoryFieldsFilled = true;
mandatoryFields.forEach(function(field) {
  if (!current[field].value) {
    isMandatoryFieldsFilled = false;
    gs.addErrorMessage("Please fill the mandatory field " + field);
  }
});
if (!isMandatoryFieldsFilled) {
  current.setAbortAction(true); // prevent incident creation
  gs.eventQueue("incident.mandatory_fields_missing", current, current.caller_id); // send notification to the user who tried to create the incident
}

 

 

If my response helps you to resolve the issue close the question by Accepting solution and hit 👍thumb icon. From Correct answers others will get benefited in future.

 

Thanks,

Ratnakar

Hi Ratnakar,

 

The first BR runs everytime and throws error even if mandatory fields are filled. I have updated the mandatory fields as required.

 

Below is the script:  Could you please help?

(function executeRule(current, previous /*null when async*/) {
  var mandatoryFields = [ 'business_service', 'assigned_to', 'short_description', 'assignment_group']; // list of mandatory fields
  var isMandatoryFieldsFilled = true;
  mandatoryFields.forEach(function(field) {
    if (!current[field].value) {
      isMandatoryFieldsFilled = false;
      gs.addInfoMessage("Please fill the mandatory field " + field);
    }
  });
  if (!isMandatoryFieldsFilled) {
    current.setAbortAction(true); // prevent incident from auto-closing
    //gs.eventQueue("incident.mandatory_fields_missing", current, current.assignment_group); // send notification to the assigned group
  }
})(current, previous);

 

 

The BR runs every time when Incident saved or when we try to save. Even when mandatory fields are filled all.

 

Could you please check if i am missing something in If condition of script?

 

Thanks in Advance,

Hritik