Business rule validation STAY ON FORM after blocked submission

leslie8
Mega Expert

I am using a Business Rule for server side validation.


If there is an error in the user entry, I want to have the Business Rule stop the form submission AND STAY ON THE FORM after they press the submit button so that they can have a chance to correct the error and re-submit the form.

Right now the business rule is running and it stops data from being entered into the database BUT it goes to a blank page after form submission. I want to STAY ON THE SAME FORM that they were working on with their entries retained.

The line action.setReturnURL(current); does not work.

Business Rule

loanerDates();

function loanerDates() {

gs.addInfoMessage('Record submission aborted.'); // error message

current.setAbortAction(true); // stop the form submission

action.setReturnURL(current);

}

Any suggestions?

5 REPLIES 5

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Leslie,



I think you can write a client script on change and then do the validation which will be solve the issue.


Please let me know if you have any questions.


HI Pradeep thank you for the suggestion. However, I have client scripts already.



I want to use a Business Rule since that is a server-side script and will run even if client scripts are disabled. The reason for using a BR in addition to client script is listed in my previous post   https://community.servicenow.com/thread/182751


leslie8
Mega Expert

This might be a bug that I am running into. I cant redirect while also stopping the form submission in the business rule. Ugh! Does anyone have any ideas?


ServiceNow KB: gs.setRedirect() in combination with current.setAbortAction(true) not executed (KB053...


Julian Hoch
ServiceNow Employee
ServiceNow Employee

The correct script would be:


action.setRedirectURL(current);



The return URL specifies where the user is redirected if he uses back on the next page.


See also:


Difference between setRedirectURL() and setReturnURL()