Business Rule should kick off before UI Action Update

kemmy1
Tera Guru

I have a simple UI Action that is a form button that closes a change record:

moveToClosedUnAuth();
function moveToClosedUnAuth(){
current.state = 3;
current.update();
action.setRedirectURL(current); / 
}

I have a before Business Rule that checks some things and if they don't check out, gives an error and sets the state back to the previous state:

gs.addErrorMessage('This is a message);
current.state = previous.state;

The problem is the UI Action closes the change (sets the state to "3") and THEN my business rule seems to kick off and give the user and error (that's too late).

Why isn't the business rule kicking off at the time of the UI Action update an sending it to the previous state?

Lisa

1 ACCEPTED SOLUTION

Jon Barnes
Kilo Sage

in your business rule, you would generally use a current.setAbortAction(true); to abort the action. in that case, you don't need to set anything back to previous state.

 

example would be something like:

 

if (someFailureConditionMet) {

  current.setAbortAction(true);

  gs.addErrorMessage('your error message');

}

 

Also, your error message line has an unterminated string:

 

gs.addErrorMessage('This is a message');

View solution in original post

3 REPLIES 3

Jon Barnes
Kilo Sage

in your business rule, you would generally use a current.setAbortAction(true); to abort the action. in that case, you don't need to set anything back to previous state.

 

example would be something like:

 

if (someFailureConditionMet) {

  current.setAbortAction(true);

  gs.addErrorMessage('your error message');

}

 

Also, your error message line has an unterminated string:

 

gs.addErrorMessage('This is a message');

SanjivMeher
Kilo Patron
Kilo Patron

I think you should include the validations in the UI action itself, so that you dont have to perform the action update also.


Please mark this response as correct or helpful if it assisted you with your question.

Upender Kumar
Mega Sage

hi,

Please add below code in your before insert/update BR

current.setAbortAction(true);

gs.addInfoMessage("Please close child tasks.");
gs.setRedirectURL(current);