Problem records are closed, but problem tasks are still open

PavanKumar Raja
Tera Contributor

I have an issue with problem records, when I click on resolve, the problem record is closing directly without checking the active open problem tasks, I need to stop the problem resolving, problem resolve will happen only when the active/open tasks are closed, please help us with the solution.

1 ACCEPTED SOLUTION

Harish Kota
Kilo Sage

Hi Pavan,

 

You can achieve this by using before update Business rule.

 

In When to run add the condition as 'State changes to Resolved'

 

and in the Advanced tab, write the below code:

 

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

var gr = new GlideRecord("problem_task");
gr.addActiveQuery();
gr.addQuery("problem", current.sys_id);
gr.query();
if (gr.next()) {
gs.addErrorMessage("Please close the open Problem tasks to proceed to Resolved state");
current.setAbortAction(true);
}

})(current, previous);

 

Please hit like/Accept as Solution, if it works for you.

 

Thanks,

Harish

 

 

View solution in original post

3 REPLIES 3

Harish Kota
Kilo Sage

Hi Pavan,

 

You can achieve this by using before update Business rule.

 

In When to run add the condition as 'State changes to Resolved'

 

and in the Advanced tab, write the below code:

 

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

var gr = new GlideRecord("problem_task");
gr.addActiveQuery();
gr.addQuery("problem", current.sys_id);
gr.query();
if (gr.next()) {
gs.addErrorMessage("Please close the open Problem tasks to proceed to Resolved state");
current.setAbortAction(true);
}

})(current, previous);

 

Please hit like/Accept as Solution, if it works for you.

 

Thanks,

Harish

 

 

Excellent, Thanks harish! Solution is worked.

 

In my question, some glitch is there, but you have understood the issue and provided the solution, thanks for the help.

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @PavanKumar Raja ,

You can try below BR on problem table

Before Update

State changes to closed

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


    // Add your code here
    var grProblemTask = new GlideRecord('problem_task');
    grProblemTask.addEncodedQuery("active=true^problem="+current.sys_id);
    grProblemTask.query();
    if (grProblemTask.next()) {
        gs.addInfoMessage(gs.getMessage("Please close the task before closing the problem ticket."));
        current.setAbortAction(true);
    }

})(current, previous);

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy