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.

Prevent problem record from being closed if there are pending problem tasks on that record

abdnayeemsh
Tera Contributor

I want to prevent a problem record from closing before its related problem tasks gets closed using the below

(before update) business rule on problem table.

But it is just showing an invalid update pop up and  moving to closed state while there are still pending problem tasks. 

 

 

(function executeRule(current, previous ) {

    if (current.state.changesTo('Closed')) {
        var taskGR = new GlideRecord('problem_task'); 
        taskGR.addQuery('problem', current.sys_id);  
        taskGR.addActiveQuery();
        taskGR.query();

        if (taskGR.next()) {
            gs.addErrorMessage('Cannot close Problem. All associated Problem Tasks must be completed.');
            current.setAbortAction(true); 
        }
    }

 

})(current, previous);

 

 

 

0 REPLIES 0