Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

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

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

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

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

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.

Not applicable

It's an OOB Business Rule, found it.

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);