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.

Business rule script for finding out if all problem_task are closed for same problem?

Community Alums
Not applicable

Can anyone share a business rule script on 'problem_task' table on how to find out if all the problem task are closed for the same problem.

1 ACCEPTED SOLUTION

Harsh_Deep
Giga Sage
Giga Sage

Hello @Community Alums 

 

Please find below snip -

Harsh_Deep_0-1699274404429.png

 

 

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.

View solution in original post

5 REPLIES 5

Utpal Dutta
Tera Guru
Tera Guru

Hi Reaper,

Below is the script

 

var grProblem = new GlideRecord('problem_task');
grProblem.addQuery('problem', current.problem);
grProblem.query();

while(grProblem.next()){
//You can write the script what do you want to do will all the problem task records having same problem
}

 

If my answer helps then please mark it correct.

 

Thanks,

Utpal

Harsh_Deep
Giga Sage
Giga Sage

Hello @Community Alums 

 

Please find below snip -

Harsh_Deep_0-1699274404429.png

 

 

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.

Community Alums
Not applicable

It's an OOB Business Rule, found it.

Community Alums
Not applicable

Thank you @Utpal Dutta @Harsh_Deep for your replies

 

What I have written is quite a lengthy code compared to yours [Check below]

 

BR.PNG

 

BR Script: 

 

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

    var problemsysID = current.problem.sys_id;

    var problemTaskNotClosed = new GlideAggregate('problem_task'); // To check how many problem task are available.
    problemTaskNotClosed.addQuery('problem', current.problem);
    problemTaskNotClosed.addAggregate('Count', 'problem');
    problemTaskNotClosed.query();
    while (problemTaskNotClosed.next()) {
        var problemTaskNotClosedCount = problemTaskNotClosed.getAggregate('Count', 'problem');
    }
    gs.info("Reaper: problemTaskNotClosedCount : " + problemTaskNotClosedCount);

    var problemTaskClosed = new GlideAggregate('problem_task'); // To check how many problem task are in closed state.
    problemTaskClosed.addQuery('problem', current.problem);
    problemTaskClosed.addQuery('state', '157')
    problemTaskClosed.addAggregate('Count', 'problem');
    problemTaskClosed.query();
    while (problemTaskClosed.next()) {
        var problemTaskClosedCount = problemTaskClosed.getAggregate('Count', 'problem');
    }
    gs.info("Reaper: problemTaskClosedCount : " + problemTaskClosedCount);

    if (problemTaskNotClosedCount == problemTaskClosedCount) //check wehther all problem Task are in closed state.
        gs.info("Reaper: All Problem Task are closeed" + current.problem.number);
    else
        gs.info("Reaper: Not all Problem Task are closed" + current.problem.number);

})(current, previous);