Automatically create problem when more than 4 incidents with same CI, category & subcategory values

SanaPR
Giga Guru

Hi,

We are looking for a solution where system auto creates a problem ticket when there are more than 4 incidents are submitted for the same CI, Category and Subcategory combination , without redundancy.
Can this be achieved? Has anyone found a solution via Business rules or Flow Designer to achieve this? Need the solution run once every 10 days. Any suggestions or inputs please?

Thank you!

7 REPLIES 7

AnubhavRitolia
Mega Sage
Mega Sage

Hi @SanaPR 

 

Try below BR:

 var aggIncident = new GlideAggregate('incident');
    aggIncident.addAggregate('COUNT');
    aggIncident.addQuery('cmdb_ci', current.cmdb_ci);
    aggIncident.addQuery('category', current.category);
    aggIncident.addQuery('subcategory', current.subcategory);
    aggIncident.query();

    while (aggIncident.next()) {
        if (aggIncident.getAggregate('COUNT') >= 4 && !aggIncident.problem_id) {
            var prb = new GlideRecord('problem');
            ............
            var prbID = prb.insert();
			current.problem_id = prbID;
        } else if (aggIncident.getAggregate('COUNT') >= 4 && aggIncident.problem_id) {
            current.problem_id = aggIncident.problem_id;
        } else {
            return;
        }

    }

 

To create Problem record set values accordingly and try this it should work.

 

Or can try similar code in Scheduled Job if you want to achieve it using Scheduled Job.

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

Thank you for your response. Appreciate it very much. There seems to be couple of issues with this that I could correct with below code. But is there a way to link these 4 incidents to this newly created problem ticket? Also since it is an Insert/Update BR, it creates a new Problem ticket every time there is an update on one of the Incident records, But I needed it update since the category/subcategory/CI values may change even after incident ticket submission. Is there a way to check if a problem already exists for an Incident while updating the ticket and ignore creation of new problem if there is already one created/related.
Thank you for your reply.


Corrected script for After Insert Update Business Rule:

 
    if(!current.cmdb_ci || !current.category || !current.subcategory){
        return;
    }
    var aggIncident = new GlideAggregate('incident');
aggIncident.addAggregate('COUNT');
aggIncident.addQuery('active', true);
aggIncident.addQuery('cmdb_ci', current.cmdb_ci);
aggIncident.addQuery('category', current.category);
aggIncident.addQuery('subcategory', current.subcategory);
aggIncident.query();

while (aggIncident.next()) {
    if (aggIncident.getAggregate('COUNT') == 4 && !aggIncident.problem_id) {
        var prb = new GlideRecord('problem');

        prb.short_description = "Creating a Problem as more than 4 Incidents are created with same Configuration item, Category and SubCategory combination " + current.cmdb_ci.getDisplayValue() + "," + current.category.getDisplayValue() + "&" +current.subcategory.getDisplayValue();
        prb.state = '1';
prb.cmdb_ci = current.cmdb_ci;
prb.category = current.category;
prb.subcategory = current.subcategory;

        var prbID = prb.insert();
        current.problem_id = prbID;
    } else if (aggIncident.getAggregate('COUNT') == 4 && aggIncident.problem_id) {
        current.problem_id = aggIncident.problem_id;
    } else {
        return;
    }

}

Hi @SanaPR 

 

Yes, I just gave you sample where you can update details according to the requirement. To check Problem already exist or not also I added condition.

 

Do mark my answer as Correct if this helped you to resolved the issue.

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

sir, if my problem is close and then i got same CI issue so what should i do in that situation?