check if there is already an existing problem with that incident, if not please create a new problem

purnendu
Tera Contributor

When the state of incident is changed to on hold with reason as Awaiting problem, check if there is already an existing problem with that incident, if not please create a new problem with similar details as incident.

How it can be achieve by using business rule.

 

Thanks in advance.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@purnendu 

Do this. ensure you use correct state values in BR condition

Create a Business Rule:

Table: incident
When to run: before update
Condition: current.state == 3 && current.hold_reason == 3
Script:

(function executeRule(current, previous /*null when async*/) {
    // Check if there is already an existing problem linked to this incident
    if (!current.problem_id) {
        // Create a new Problem record
        var problem = new GlideRecord('problem');
        problem.initialize();
        problem.short_description = current.short_description;
        problem.description = current.description;
        problem.insert();
        // Link the newly created problem to the incident
        current.problem_id = problem.sys_id;
    }
})(current, previous);

This script checks if there is an existing problem linked to the incident. If not, it creates a new problem with similar details and links it to the incident.

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

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@purnendu 

Do this. ensure you use correct state values in BR condition

Create a Business Rule:

Table: incident
When to run: before update
Condition: current.state == 3 && current.hold_reason == 3
Script:

(function executeRule(current, previous /*null when async*/) {
    // Check if there is already an existing problem linked to this incident
    if (!current.problem_id) {
        // Create a new Problem record
        var problem = new GlideRecord('problem');
        problem.initialize();
        problem.short_description = current.short_description;
        problem.description = current.description;
        problem.insert();
        // Link the newly created problem to the incident
        current.problem_id = problem.sys_id;
    }
})(current, previous);

This script checks if there is an existing problem linked to the incident. If not, it creates a new problem with similar details and links it to the incident.

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