Some PDIs are currently unavailable, and PDI actions are paused. View the latest updates here. Read More

problem should not resolve if associated ptask is open

ashimghosh1
Mega Contributor

I want to create business rule like if the problem associated Ptask is not resolved then problem should not be resolved.

5 REPLIES 5

Tanushree Maiti
Tera Patron

Hi @ashimghosh1 

 

Try This:

 

Name : Restrict Problem Resolution with Open Tasks

Table:  Problem [problem]

Advanced    :    Checked

When  :Before

Update  :  Checked

 

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

    var taskGR = new GlideRecord('problem_task');

    taskGR.addQuery('problem', current.getUniqueValue()); 

    taskGR.addActiveQuery(); 

    taskGR.setLimit(1 ); 

    taskGR.query();

    if (taskGR.next()) {

        gs.addErrorMessage('Cannot resolve this Problem because one or more associated Problem Tasks are still open.');

        current.setAbortAction(true); 

    }

})(current, previous);

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

Tejas Adhalrao
Kilo Sage

Hi @ashimghosh1  ,

You'll need a before-update business rule on the problem table. 

(function executeRule(current, previous) {
    
    // Only check when status is changing to resolved (6)
    if (current.status == '6' && previous.status != '6') {
        
        // Query for any child problems/ptasks that are still open
        var gr = new GlideRecord('problem');
        gr.addQuery('parent', current.sys_id);
        gr.addQuery('status', '!=', '6');
        gr.query();
        
        if (gr.getRowCount() > 0) {
            gs.addErrorMessage('Cannot resolve. You have ' + gr.getRowCount() + ' open subtask(s) that need to be resolved first.');
            current.setAbortAction(true);
        }
    }
    
})(current, previous);

 '6' usually means "Resolved" but verify that in your instance. 

 

If you found my solution helpful, please mark it as Helpful and Accept Solution.

The field is 'state', not 'status', or 'active'. And OOB values are 106: "Resolved", 107: "Closed".

Nishant8
Tera Sage

Hello @ashimghosh1 , Could you please try the below approach and share the feedback?

- Configure the BR as below:

Nishant8_0-1784132142312.png

- Under the Advanced tab, use the below script:

(function executeRule(current, previous) {
    var openTasks = new GlideRecord('problem_task');
    openTasks.addQuery('problem', current.getUniqueValue());
    openTasks.addQuery('state', '!=', '157');
    openTasks.query();

    if (openTasks.hasNext()) {
        var count = 0;
        while (openTasks.next()) {
            count++;
        }
        gs.addErrorMessage('Cannot close this Problem. There are ' + count + ' associated Problem Task(s) that are not yet closed.');
        current.setAbortAction(true);
    }
})(current, previous);

 

Regards,

Nishant