to avoid to create duplicate problem records from the major incidents

sureshp89882164
Tera Contributor

I have a business rule written that whenever a P1/P2/Managed P3 incident is resolved then a problem record will be created automatically. The problem record is being generated correctly (like major problem will create for P1/P2 incidents is resolved and non-major problem will create for Managed P3 incident is resolved), but there are some times where duplicate problem records are being created with different problem numbers.

What condition should I put in my BR to avoid creation of duplicate problem records?

 

*Please find the attached screen shot of when to run business rule conditions.

 

Business Rule is below:

(function executeRule(current, previous /*null when async*/ ) {

    var prob = new GlideRecord("problem");
    prob.first_reported_by_task = current.sys_id;
    prob.short_description = current.short_description;
    prob.description = current.description;
    prob.cmdb_ci = current.cmdb_ci;
    prob.impact = current.impact;
    prob.urgency = current.urgency;
    prob.u_category = current.category;
    prob.business_service = current.business_service;
    if (current.major_incident_state == "accepted" && (current.priority == 1 || current.priority == 2)) {
        prob.major_problem = true;
        prob.assignment_group = gs.getProperty('command.centre.incident.communications');
    }
    else {
        prob.major_problem = false;
        prob.assignment_group = current.assignment_group;
    }
    prob.u_caused_by_change = current.caused_by;
    prob.priority = current.priority;
    prob.company = current.company;
    prob.sys_domain = current.sys_domain;
    prob.insert();
    var sysID = prob.sys_id;
    current.problem_id = sysID;
    current.setWorkflow(false);
    current.update();
    current.setWorkflow(true);
    gs.addInfoMessage("Problem " + prob.number + " has been created.");

})(current, previous);
8 REPLIES 8

Ehab Pilloor
Mega Sage

Hi @sureshp89882164,

 

You can try to see and check if First reported by task is not filled then create a problem record and attach it to incident. 

var prob = new GlideRecord("problem");
    prob.addQuery("first_reported_by_task", current.sys_id);
    prob.query();

    if (!prob.next()) {  // Only create a new problem record if one does not already exist
        prob.initialize();
    prob.first_reported_by_task = current.sys_id;
    prob.short_description = current.short_description;
    prob.description = current.description;
    prob.cmdb_ci = current.cmdb_ci;
    prob.impact = current.impact;
    prob.urgency = current.urgency;
    prob.u_category = current.category;
    prob.business_service = current.business_service;
    if (current.major_incident_state == "accepted" && (current.priority == 1 || current.priority == 2)) {
        prob.major_problem = true;
        prob.assignment_group = gs.getProperty('command.centre.incident.communications');
    }
    else {
        prob.major_problem = false;
        prob.assignment_group = current.assignment_group;
    }
    prob.u_caused_by_change = current.caused_by;
    prob.priority = current.priority;
    prob.company = current.company;
    prob.sys_domain = current.sys_domain;
    prob.insert();
    var sysID = prob.sys_id;
    current.problem_id = sysID;
    current.setWorkflow(false);
    current.update();
    gs.addInfoMessage("Problem " + prob.number + " has been created.");
    current.setWorkflow(true);

Regards,

Ehab Pilloor 

This one is working fine. It will creating only one problem record at a time. But it is creating non-major problem record instead of major problem record creation when P1/P2 incident resolved.

@sureshp89882164 

If condition is not working as expected.

You can check if Accepted state value is the same in script and  if priority value is integer or string.

In the above script, priority value is given as integer.

 

If you found it useful, kudos would be appreciated.

 

Regards,

Ehab Pilloor

@sureshp89882164 

you can ensure business rule runs only for major incident

Add proper BR conditions.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader