Create a business rule / onsubmit script to restrict the form from updating/submitting

Uttam Sai
Tera Contributor

Hi Team,

 

I am using an Onchange client script on outage form to show error message on two fields. But the issue is that i am able to save or submit the form despite the error. Can we create  a business rule / onsubmit client script to restrict the form from updating/submitting if there are field error message .Could you please let me know what alternate ways we can try to achieve this.

 

Thank you 

14 REPLIES 14

Uttam Sai
Tera Contributor

I have been referring this --> Question , but cannot find the exact answer.

Nootan Bhat
Kilo Sage

Hi @Uttam Sai,

You can create before business rule which will show the error message and abort the save action.

Or else use the onSubmit client script to return false.

Refer: https://servicenowguru.com/scripting/stopping-record-submission-servicenow/

https://www.servicenow.com/community/itsm-forum/onsubmit-client-script-to-prevent-form-submission/m-...

https://www.servicenow.com/community/developer-forum/how-to-restrict-submission-of-form-from-onchang....

 

If still wish to use the onchange client script. you can set the field value back to previous value and show the message for the same. This can restrict the field value change. Make sure that this changes does not goes on loop in the client script.

 

Let me know if it helped.

 

Thanks,

 

shyamkumar VK
Kilo Patron

Hello @Uttam Sai ,

Field messages gets displayed but it wont stop you in saving the record , if you want to do some validations use Submit client script and use "return false" to abort the submission

 

Ex : if(a=b){

return true; // allows saving record

else

return false // aborts saving record

==================================

Also you can use before update BR and do validation and if it return false use current.setAbortAction(true); to save the record

Please mark this as helpful and accept as a solution if this resolves your Ask.
Regards,

Shyamkumar

Hari Prasath
Tera Guru

Hi @Uttam Sai 

 

We can use the business rule and setAbortAction() method to restrict the form submission.  If you explain your requirement clearly I can provide you with the script.

 

Please mark my answer as helpful, if it helped you accordingly!

 

Thanks,

Hari