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

Ankur Bawiskar
Tera Patron
Tera Patron

@sureshp89882164 

you can check if problem already exists for this INC

something like this

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

    var prob = new GlideRecord("problem");
    prob.addQuery('first_reported_by_task', current.sys_id);
    prob.query();
    if (prob.hasNext())
        return;
    else {
        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();
        current.setWorkflow(true);
        gs.addInfoMessage("Problem " + prob.number + " has been created.");
    }

})(current, previous);

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

@sureshp89882164 

Hope you are doing good.

Did my reply answer your question?

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

Ankur Bawiskar
Tera Patron
Tera Patron

@sureshp89882164 

whenever a Major incident is getting resolved, then system creates a problem record automatically.

This is OOTB behavior.

it comes from this playbook "Major Incident Process", You can see after Resolve step, it's creating Problem Record

In the Step 8 it calls this "Major Incident Playbook - Create a Problem from Incident" subflow

This subflow calls another flow action "Create Problem Record from Incident" where the problem is created

1) Subflow

 

AnkurBawiskar_0-1750154727883.png

 

 

2) Action

AnkurBawiskar_1-1750154727883.png

 

 

1) either deactivate that subflow

OR

2) Remove that Step 8, remember you will have to update the playbook in the correct scope

AnkurBawiskar_2-1750154727880.png

 

 

OR

3) Update that flow action

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

Thank you. Let me check on this code.