How to restrict closure of problem record if task open?

jugantanaya
Tera Contributor

Hi,

Requirement is to restrict the closure of the problem record if any task is open.

One Business rule i have created but problem manager and problem admin able to close the problem record.

 

Business Rule:(Update)

When: before

State = Resolved

Script:

(function executeRule(current, previous /*null when async*/) {
var rec = new GlideRecord('problem_task');
rec.addQuery('problem', current.sys_id);
rec.addQuery('active', true);
rec.query();
//If any of the tasks are active abort the submission
if (rec.hasNext()) {
    gs.addInfoMessage('Submission aborted due to active child tasks.');
    current.setAbortAction(true);
}
}) (current, previous);

 

1 ACCEPTED SOLUTION

M Iftikhar
Mega Sage

 

Hi @jugantanaya,

You can add a role-based check directly in your Business Rule like this:

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

    if (gs.hasRole('problem_manager') || gs.hasRole('problem_admin')) {
        var rec = new GlideRecord('problem_task');
        rec.addQuery('problem', current.sys_id);
        rec.addQuery('active', true);
        rec.query();

        if (rec.hasNext()) {
            gs.addErrorMessage('You cannot resolve or close this Problem because there are still active Problem Tasks.');
            current.setAbortAction(true);
        }
    }

})(current, previous);


This ensures Problem Managers and Admins are also prevented from closing if tasks are still active.

 

Thanks & Regards,  
Muhammad Iftikhar 
 
If my response helped, please mark it as the accepted solution so others can benefit as well. 

View solution in original post

6 REPLIES 6

M Iftikhar
Mega Sage

 

Hi @jugantanaya,

You can add a role-based check directly in your Business Rule like this:

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

    if (gs.hasRole('problem_manager') || gs.hasRole('problem_admin')) {
        var rec = new GlideRecord('problem_task');
        rec.addQuery('problem', current.sys_id);
        rec.addQuery('active', true);
        rec.query();

        if (rec.hasNext()) {
            gs.addErrorMessage('You cannot resolve or close this Problem because there are still active Problem Tasks.');
            current.setAbortAction(true);
        }
    }

})(current, previous);


This ensures Problem Managers and Admins are also prevented from closing if tasks are still active.

 

Thanks & Regards,  
Muhammad Iftikhar 
 
If my response helped, please mark it as the accepted solution so others can benefit as well. 

Hi @M Iftikhar ,

 

Thanks for your solution, it's working.

 

Regards,

Juganta

RaghavSh
Kilo Patron

You will have to check the count, because Problem can have multiple tasks and this will just check the 

1st task as you are using if. This is not related to role as you mentioned.

 

Try below:

(function executeRule(current, previous /*null when async*/) {
var rec = new GlideRecord('problem_task');
rec.addQuery('problem', current.sys_id);
rec.addQuery('active', true);
rec.query();
if (rec.getRowCount()>0) {
    gs.addInfoMessage('Submission aborted due to active child tasks.');
    current.setAbortAction(true);
}
}) (current, previous);

 


Raghav
MVP 2023

aruncr0122
Tera Contributor

Hi @jugantanaya ,

 

Your Business Rule (BR) approach is correct (server-side enforcement is key for reliability), but the issue seems to be in the condition of the rule. It's set to trigger only when State = Resolved , but "closure" often means changing to Closed. If problem managers or admins are updating directly to Closed (skipping Resolved), the rule won't fire, which explains why it works for standard users but not them.

Update the condition to state changes to Closed this triggers specifically when the state is changing to Closed, no matter what it was before.