The CreatorCon Call for Content is officially open! Get started here.

Checking for open problem tasks when trying to close problem records

mflexman
Kilo Contributor

Im trying to get a business rule to check if a problem record has any pending problem tasks when a user tries to close the record down. My script is as follows:

//Query for associated tasks to see if they are pending
var target = new GlideRecord('problem_task');
target.addQuery('problem', current.number);
target.addQuery('state', 3);
target.query();

if(target.hasNext()){
//Is the user trying to resolve or cancel the problem record?
if ((current.problem_state == 4) || (current.problem_state == 5)){
gs.addInfoMessage("You have open tasks which must be completed before this record can be closed");
//return the state back to what it was
current.problem_state = previous.problem_state;
}
}
else{
gs.addInfoMessage("All tasks have been completed");
}

It can find a match on the state but doesn't appear to be able to match the problem record number with that recorded within the child task. Ive spent far too long trying to work this out which my gut feeling is telling me is rather a simple oversight.

Can anyone help please?

Thanks in anticipation
Mark

11 REPLIES 11

Baggies
Kilo Guru

Hi Terry, thanks for the reply.
I did try the final working BR from mflexman. Which worked to an extent, but my ui action - close problem, still went ahead and set the state to closed/resolved (4).
I didnt have any conditions on the BR, but I will give it a try as you suggested.

I did think of an easy route too, that was to let the workflow do the checking, and when all tasks are complete, have it set the states for me. Having a Close Problem button would have been nice though.

I thought I could just add the above script to the UI Action and then add

current.problem_state = 4;
current.update();
to the else section. Cheers, and Thanks again. I'll post any results for reference by others.
mark


If this is a UI Action that calls the 'Global' BR then the BR does NOT need the condition. You should only call the function in the UI Action if you need it. Are you running the UI Action 'Client_Side' or 'Server'?