Problem Resolve

shabbir9
Tera Contributor

Hi Team,

 

on problem we have related list like incident,change,problem task ..there is one functionality is running that without closing the related tasks problem should not be resolved "You must have to close all task before you can resolve this problem"

now the requirement is customer wants to resolve the problem when the related change is in" complete" state only they don't want to wait until the change is closed can anyone suggest me how to achieve this 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@shabbir9 

try this in before update BR on problem table, please enhance as per your requirement

Condition: State Changes to Close/Resolved

Script:

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

    // Check Problem Tasks
    var taskGR = new GlideRecord('problem_task');
    taskGR.addQuery('problem', current.sys_id);
    taskGR.addActiveQuery();
    taskGR.setLimit(1);
    taskGR.query();
    if (taskGR.hasNext()) {
        gs.addErrorMessage('All Problem Tasks must be closed before resolving the Problem.');
        current.setAbortAction(true);
        return;
    }

    // Check Incidents
    var incidentGR = new GlideRecord('incident');
    incidentGR.addQuery('problem_id', current.sys_id);
    incidentGR.addActiveQuery();
    incidentGR.setLimit(1);
    incidentGR.query();
    if (incidentGR.hasNext()) {
        gs.addErrorMessage('All related Incidents must be closed before resolving the Problem.');
        current.setAbortAction(true);
        return;
    }

    // Check Changes
    var changeGR = new GlideRecord('change_request');
    changeGR.addQuery('parent', current.sys_id);
    changeGR.addQuery('state', '!=', '3'); // Only block if not in "closed"
    changeGR.query();
    if (changeGR.hasNext()) {
        gs.addErrorMessage('All related Changes must be at least in the "Closed" state before resolving the Problem.');
        current.setAbortAction(true);
        return;
    }

})(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

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@shabbir9 

try this in before update BR on problem table, please enhance as per your requirement

Condition: State Changes to Close/Resolved

Script:

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

    // Check Problem Tasks
    var taskGR = new GlideRecord('problem_task');
    taskGR.addQuery('problem', current.sys_id);
    taskGR.addActiveQuery();
    taskGR.setLimit(1);
    taskGR.query();
    if (taskGR.hasNext()) {
        gs.addErrorMessage('All Problem Tasks must be closed before resolving the Problem.');
        current.setAbortAction(true);
        return;
    }

    // Check Incidents
    var incidentGR = new GlideRecord('incident');
    incidentGR.addQuery('problem_id', current.sys_id);
    incidentGR.addActiveQuery();
    incidentGR.setLimit(1);
    incidentGR.query();
    if (incidentGR.hasNext()) {
        gs.addErrorMessage('All related Incidents must be closed before resolving the Problem.');
        current.setAbortAction(true);
        return;
    }

    // Check Changes
    var changeGR = new GlideRecord('change_request');
    changeGR.addQuery('parent', current.sys_id);
    changeGR.addQuery('state', '!=', '3'); // Only block if not in "closed"
    changeGR.query();
    if (changeGR.hasNext()) {
        gs.addErrorMessage('All related Changes must be at least in the "Closed" state before resolving the Problem.');
        current.setAbortAction(true);
        return;
    }

})(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