how to restrict submission of form from onchange in servicnow

Abhinab Achary1
Tera Guru

Hi All,

I want to write something in an OnChange() client script so that it should not allow user to submit the form (CATALOG ITEM form).

how to achieve it without writting a separate onsubmit()

Thanks,

Abhinab

1 ACCEPTED SOLUTION

oliverschmitt
ServiceNow Employee
ServiceNow Employee

Well, what Michael says is the javascript way, which basically "hacks it away" and it could break after an upgrade due to the fact that we dont support the HTML element structure. Basically it is a bad practice and will fall of a report like a config review if the customer requests it.



I am not sure what the use case is and why there is an issue in creating an onSubmit script, which whole purpose is to do exactly that. The thing you need to understand is that the script are bound to certain browser events and only fired and evaluated during runtime in especially those situations. If you'd like to read more check this out: An Introduction To DOM Events — Smashing Magazine


View solution in original post

4 REPLIES 4

michal29
Mega Guru

Hello Ahbinab,



You could get get button and hide/disable it, so that the form could not be submitted,


Like:


if(YOUR_CONDITION == true){


$('BUTTON_ELEMENT_ID').hide();


} else {


$('BUTTON_ELEMENT_ID').show();


}



Regards,


Michal


Swapnil Bhakar1
Mega Guru

Hi Abhinab,



Yes you can achieve this without writing onSubmit client script.



Make your onchange field mandatory. If user trying to enter wrong value in onChange field clear the field value it means when user trying to submit the form field remains empty i.e. mandatory and it will restrict the form submission.



Regards,


Swapnil



PS: Hit like, Helpful or Correct depending on the impact of the response


oliverschmitt
ServiceNow Employee
ServiceNow Employee

Well, what Michael says is the javascript way, which basically "hacks it away" and it could break after an upgrade due to the fact that we dont support the HTML element structure. Basically it is a bad practice and will fall of a report like a config review if the customer requests it.



I am not sure what the use case is and why there is an issue in creating an onSubmit script, which whole purpose is to do exactly that. The thing you need to understand is that the script are bound to certain browser events and only fired and evaluated during runtime in especially those situations. If you'd like to read more check this out: An Introduction To DOM Events — Smashing Magazine


zica
Giga Guru

Acharyya,



I believe that you want to highlight that there is an "issue" while changing a value of a field before the user clicks on the "save" button,


Please go through this article, it may help you to solve the issue : http://www.servicenowguru.com/scripting/stopping-record-submission-servicenow/