Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Auto creation of problem tickets

Mantautas
Tera Contributor

Dear Community members,

 

We have a task to automate our problem management process. Our goal is to link similar several incidents to existing Problem record. Those several incidents would have similar patterns.

 

Question: Are there any possibilities in ServiceNow to automatically link similar incidents to existing Problem record? Those incident would have several things in common: 1. Same business_service name, and 2. Similar Description with same keywords (however description would not match fully for all incidents). 

 

Please share you experience and thoughts.

 

Regards,

Mantautas.

3 REPLIES 3

Eshwar Reddy
Kilo Sage

Hi,

 

Let me know if this works:

Create after BR -> 'Insert' or 'updated'

(function executeRule(current, previous) {
    var category = current.category.getDisplayValue();
    var subcategory = current.subcategory.getDisplayValue();

    var gr = new GlideRecord('incident');
    gr.addActiveQuery();
    gr.addQuery('category', category);
    gr.addQuery('subcategory', subcategory);
    gr.addQuery('sys_id', '!=', current.sys_id);
    gr.query();

    var similarIncidentCount = gr.getRowCount();
    var threshold = 3;

    if (similarIncidentCount >= threshold) {
        var problemGr = new GlideRecord('problem');
        problemGr.addQuery('category', category);
        problemGr.addQuery('subcategory', subcategory);
        problemGr.query();

        if (!problemGr.next()) {
            problemGr.initialize();
            problemGr.short_description = 'Multiple incidents with the same category and subcategory';
            problemGr.description = 'Multiple incidents with the same category and subcategory have been reported.';
            var problemSysId = problemGr.insert();

            if (problemSysId) {
                while (gr.next()) {
                    gr.problem_id = problemSysId;
                    gr.update();
                }
                gs.info('Problem ticket created: ' + problemSysId);
            } else {
                gs.error('Failed to create problem ticket');
            }
        }
    }
})(current, previous);

 

Regards,

Eshwar

Thank you Eshwar for this. I actually edited my original posting a bit.

This would be linking several similar incidents (having same business_service and having similar key words/patterns in decription) to problem record which can already exists. 

 

Regards,
Mantautas.

 

 

@Mantautas 

 

After insert/Update BR

 

 

var bs= current.business_service;

if (bs) {

var gr = new GlideRecord('incident'); gr.addQuery('business_service', bs); gr.query();

While(gr.next()){

    var pGR = new GlideRecord('problem');

    pGR.addQuery('business_service', gr.business_service);

  pGR.query();   

    while (GR.next()) {

        var pDes = pGR.description.toString();

        var incDesc = gr.description.toString();

        var x= pDes.split(' ');

        var flag =false;

        for (var i = 0; i < x.length; i++) {

            if (incDesc.indexOf(x[i]) != -1) {

                flag= true;

                break;

            }

        }

        if (flag==true) {

            gr.problem_id= pGR.sys_id; 

            gr.update();

        }

    }

}