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

Not applicable

Hi,

I believe the main problem is the line

target.addQuery('problem', current.number);

that should be

target.addQuery('problem', current.sys_id);

Further I would suggest to make use of current.setAbortAction(true);
instead of current.problem_state = previous.problem_state;


mflexman
Kilo Contributor

Thanks Laurens 🙂


mflexman
Kilo Contributor

Just incase anyone else would find it useful - final version of the script that works perfectly is

//Query problem_task table to see if there are any active tasks
var target = new GlideRecord('problem_task');
target.addQuery('problem', current.sys_id);
//search for any task - Open or On Hold
target.addQuery('state', 1).addOrCondition('state', 10);
target.query();

if(target.hasNext()){
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");
current.setAbortAction(true);
}

else{
//gs.addInfoMessage("All tasks have been completed");
}
}


Baggies
Kilo Guru

Hi,
I am trying to do this also when a user click the Close problem button. Did you put any condition on the Business rule? the solution you provided does the check for open tasks okay, but still closes the task.
My states for problem are :
1 -open
15- assessment
25 proposal
35 - implementation
4 - closed/resolved

my problem task states are:
1 - open
12 - pending change
2- work in progress
3-- closed complete
4 - closed incomplete
7 - close skipped.

i think it is the line " if ((current.problem_state == 4) || (current.problem_state == 5)){ " that is tripping me up. Many thanks for any response. mark s.