Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Need to find the similar incidents based on short description or configurtion item.

sai9845
Tera Contributor

Need to find the similar incidents based on short description or configurtion item. If found the similar incidents create a problem ticket with those incidents numbers and ci value. And attach the incidents and ci's in the related list of the problem ticket. And need to create a schelude on weekly basis to avoid duplication of problem ticket creation. This is the use case for creation of Agentic AI. Pls help me how to achive this.

1 ACCEPTED SOLUTION

(function execute(inputs, outputs) {

    // ----------------------------
    // 1. Read primary incident NUMBER
    // ----------------------------
    var primaryNumber = String(inputs.primary_incident_sys_id || '');
    if (!primaryNumber) {
        outputs.status = "error";
        outputs.message = "Primary incident number missing.";
        return;
    }

    // ----------------------------
    // 2. Parse similar incidents (STRING → ARRAY)
    // ----------------------------
    var numbers = [];
    var similar = inputs.similar_incident_sys_ids;

    if (typeof similar === 'string') {
        try {
            similar = JSON.parse(similar);
        } catch (e) {
            similar = [];
        }
    }

    if (Array.isArray(similar)) {
        for (var i = 0; i < similar.length; i++) {
            if (similar[i].recordNumber)
                numbers.push(String(similar[i].recordNumber));
        }
    }

    if (numbers.indexOf(primaryNumber) === -1)
        numbers.push(primaryNumber);

    if (!numbers.length) {
        outputs.status = "error";
        outputs.message = "No incidents provided.";
        return;
    }

    // ----------------------------
    // 3. Get PRIMARY incident
    // ----------------------------
    var primaryInc = new GlideRecord('incident');
    if (!primaryInc.get('number', primaryNumber)) {
        outputs.status = "error";
        outputs.message = "Primary incident not found.";
        return;
    }

    var shortDesc = String(primaryInc.short_description);

    // ----------------------------
    // 4. Find existing Problem by short_description
    // ----------------------------
    var chosenProblemId = "";
    var chosenProblemNumber = "";
    var isNew = false;

    var prbGR = new GlideRecord('problem');
    prbGR.addQuery('short_description', shortDesc);
    prbGR.orderByDesc('sys_created_on');
    prbGR.setLimit(1);
    prbGR.query();

    if (prbGR.next()) {
        chosenProblemId = prbGR.getUniqueValue();
        chosenProblemNumber = String(prbGR.number);
    }

    // ----------------------------
    // 5. Create Problem if NOT found
    // ----------------------------
    if (!chosenProblemId) {
        var newPrb = new GlideRecord('problem');
        newPrb.initialize();
        newPrb.short_description = shortDesc;
        newPrb.description =
            "Auto-created from Virtual Agent\n\n" +
            "Primary Incident: " + primaryNumber + "\n\n" +
            "Related Incidents:\n" + numbers.join("\n");

        newPrb.cmdb_ci = primaryInc.cmdb_ci;
        newPrb.priority = primaryInc.priority;

        chosenProblemId = newPrb.insert();
        chosenProblemNumber = String(newPrb.number);
        isNew = true;
    }

    // ----------------------------
    // 6. Attach ALL incidents
    // ----------------------------
    var linkedNumbers = [];

    var incGR = new GlideRecord('incident');
    incGR.addQuery('number', 'IN', numbers.join(','));
    incGR.query();

    while (incGR.next()) {
        incGR.problem_id = chosenProblemId;
        incGR.update();
        linkedNumbers.push(String(incGR.number));
    }

    // ----------------------------
    // 7. Outputs
    // ----------------------------
    outputs.problem_number = chosenProblemNumber;
    outputs.problem_sys_id = chosenProblemId;
    outputs.is_new_problem = isNew;
    outputs.incidents_linked = linkedNumbers;
    outputs.status = "success";
    if (isNew) {
    outputs.message =
        "A new Problem " + chosenProblemNumber +
        " has been created and all related incidents have been successfully linked.";
} else {
    outputs.message =
        "Similar incidents have been successfully associated with existing Problem " +
        chosenProblemNumber + ".";
}
})(inputs, outputs);

 

 

use this script as a flow action , it will all similar incident to prb

View solution in original post

8 REPLIES 8

hey @sai9845 

check your inbox.

(function execute(inputs, outputs) {

    // ----------------------------
    // 1. Read primary incident NUMBER
    // ----------------------------
    var primaryNumber = String(inputs.primary_incident_sys_id || '');
    if (!primaryNumber) {
        outputs.status = "error";
        outputs.message = "Primary incident number missing.";
        return;
    }

    // ----------------------------
    // 2. Parse similar incidents (STRING → ARRAY)
    // ----------------------------
    var numbers = [];
    var similar = inputs.similar_incident_sys_ids;

    if (typeof similar === 'string') {
        try {
            similar = JSON.parse(similar);
        } catch (e) {
            similar = [];
        }
    }

    if (Array.isArray(similar)) {
        for (var i = 0; i < similar.length; i++) {
            if (similar[i].recordNumber)
                numbers.push(String(similar[i].recordNumber));
        }
    }

    if (numbers.indexOf(primaryNumber) === -1)
        numbers.push(primaryNumber);

    if (!numbers.length) {
        outputs.status = "error";
        outputs.message = "No incidents provided.";
        return;
    }

    // ----------------------------
    // 3. Get PRIMARY incident
    // ----------------------------
    var primaryInc = new GlideRecord('incident');
    if (!primaryInc.get('number', primaryNumber)) {
        outputs.status = "error";
        outputs.message = "Primary incident not found.";
        return;
    }

    var shortDesc = String(primaryInc.short_description);

    // ----------------------------
    // 4. Find existing Problem by short_description
    // ----------------------------
    var chosenProblemId = "";
    var chosenProblemNumber = "";
    var isNew = false;

    var prbGR = new GlideRecord('problem');
    prbGR.addQuery('short_description', shortDesc);
    prbGR.orderByDesc('sys_created_on');
    prbGR.setLimit(1);
    prbGR.query();

    if (prbGR.next()) {
        chosenProblemId = prbGR.getUniqueValue();
        chosenProblemNumber = String(prbGR.number);
    }

    // ----------------------------
    // 5. Create Problem if NOT found
    // ----------------------------
    if (!chosenProblemId) {
        var newPrb = new GlideRecord('problem');
        newPrb.initialize();
        newPrb.short_description = shortDesc;
        newPrb.description =
            "Auto-created from Virtual Agent\n\n" +
            "Primary Incident: " + primaryNumber + "\n\n" +
            "Related Incidents:\n" + numbers.join("\n");

        newPrb.cmdb_ci = primaryInc.cmdb_ci;
        newPrb.priority = primaryInc.priority;

        chosenProblemId = newPrb.insert();
        chosenProblemNumber = String(newPrb.number);
        isNew = true;
    }

    // ----------------------------
    // 6. Attach ALL incidents
    // ----------------------------
    var linkedNumbers = [];

    var incGR = new GlideRecord('incident');
    incGR.addQuery('number', 'IN', numbers.join(','));
    incGR.query();

    while (incGR.next()) {
        incGR.problem_id = chosenProblemId;
        incGR.update();
        linkedNumbers.push(String(incGR.number));
    }

    // ----------------------------
    // 7. Outputs
    // ----------------------------
    outputs.problem_number = chosenProblemNumber;
    outputs.problem_sys_id = chosenProblemId;
    outputs.is_new_problem = isNew;
    outputs.incidents_linked = linkedNumbers;
    outputs.status = "success";
    if (isNew) {
    outputs.message =
        "A new Problem " + chosenProblemNumber +
        " has been created and all related incidents have been successfully linked.";
} else {
    outputs.message =
        "Similar incidents have been successfully associated with existing Problem " +
        chosenProblemNumber + ".";
}
})(inputs, outputs);

 

 

use this script as a flow action , it will all similar incident to prb

NeshanthA
Tera Expert

Hi @Sai ,


Agentic AI – Automated Problem Creation Design

  • Trigger Layer – Virtual Agent / Now Assist
    The automation is triggered either from Virtual Agent or the Now Assist panel on the Incident form. The current Incident record is passed as input to the Flow for similarity evaluation and processing.

 

  • Similarity Engine – OOTB “Get Similar Records” Subflow
    The subflow retrieves the primary Incident and identifies similar active Incidents based on short description similarity, CI, and category. A similarity threshold is applied to ensure only relevant matches are returned.

 

  • Processing Layer – Custom Flow Action
    The flow first checks whether an open Problem already exists for the same CI to avoid duplicate Problem creation. If one exists, the matched Incidents are attached to it; otherwise, a new Problem is created and all related Incidents are linked using the problem_id field.

 

  • Output Layer
    The system either creates or updates the Problem record and links all matching Incidents in the related list. A confirmation message (including the Problem number and number of linked Incidents) is returned to the user.

 

Flow Summary

Virtual Agent→ Similarity Subflow→ Duplicate Check→ Create/Update Problem→ Link Incidents→ Return Status

 

This approach ensures intelligent clustering of similar Incidents while preventing duplicate Problem records.
-----------------------------------------------------------------------------------------------------------------------------------------------------

If you found this response helpful, please consider marking it as Accept as Solution and Helpful.

This will assist other community members in finding the right solution more easily and motivates me to continue contributing.

Regards,
Neshanth A

Hi @NeshanthA 

 

Thanks for sharing the architecture overview.

Have you implemented this solution in your instance?  could you please share a few screenshots of the Flow Designer setup and the Virtual Agent topic configuration for better clarity?

This would help the community understand the practical implementation details.

Looking forward to your response.

 

Thank you,
Umesh