Problem task should be closed before problem record closure

asham2
Kilo Contributor

Hi,

In problem management, when I close the problem record the associated problem task should get closed, if not it should throw an error message and abort the action....It is working fine for me but the state changes to closed, throwing an error message   and   aborting the action but still the state would remains in closed state, when I refresh or go back the state would be in open state (i.e previous state). what should I have to do to make the state field to display the previous value (i.e aborting the action)   until I close the problem task record.

Business rule:

Action:   Before update

Condition: State changes to closed

Script:

var gr = new GlideRecord('problem_task');

gr.addQuery('active','true');

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

gr.query();

if (gr.next()) {

gs.addErrorMessage('Problem cannot be closed before the problem task closure');

current.setAbortAction(true);

}

8 REPLIES 8

Shishir Srivast
Mega Sage

I am able to reproduce the same issue, but it's actually NOT saving the data,


find_real_file.png


if you reload the form (hit F5 to right click on the form and hit reload) then you can see the state is still open.


find_real_file.png


Hi Shishir,



Instead of going till business rule, best way would be not to show close problem button on the form if you already have it for form closure.



If you are allowing user to change the states, then you can write a client script do the synchronous ajax call validate the tasks whether they are open or not.


if open then set state back to oldvalue and if all closed the let them change back to closed state.



thanks and regards,


Girish Deshpande


Nikita35
Kilo Guru

Hey

I am facing same issue, Did you find something to fix this?

Display of the State is Closed which is quite confusing.

Service_RNow
Mega Sage

HI,

please try code:

BR - problem

before and update

code:

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

// Add your code here
var gr = new GlideRecord('problem_task');

gr.addQuery('active','true');

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

gr.query();

if (gr.next()) {

gs.addErrorMessage('Problem cannot be closed before the problem task closure');

current.setAbortAction(true);

}

})(current, previous);