Business rue to abort action

rahul0602
Kilo Contributor

HI All

I have been trying to write a BR which aborts the action     when Ptasks are not closed and   problem state changes to resolved. It is working fine till here, but I need to set the state back to previous one.

before   update BR on Problem

var ptask = new GlideRecord('problem_task');

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

ptask.addQuery('state', 'NOT IN', '6,7');   //for Closed Skipped and Closed Complete,

ptask.query();

if (ptask.next()) {

gs.addErrorMessage('Please close   all the Problem tasks before resolving/ closing the Problem');

current.setAbortAction(true);

current.state = previous.state;}

It is not letting the user to set state= resolved, which is expected...but current.state = previous.state, this is not happening

7 REPLIES 7

Justin Abbott
Giga Guru

The state should remain unchanged in the database.



As a visual indication, you could use g_scratchpad to set the state back when the form reloads.



In your business rule, include g_scratchpad.previousState = previous.state;



Then, in an onLoad client script...



if (g_scratchpad.previousState) {


      g_form.setValue('state', g_scratchpad.previousState);


}


It is revering back to previous state when the form is reloaded by itself, but I need to have such thing when Problem state to resolved is aborted...and isntead of showing resolved on the form, it should show the previous state.


Is it possible by scratch pad?


I had thought so with my original post, but I have since proved myself wrong. Sorry about that! I should've tested my theory before suggesting it.