Reputation: 2471
I am writing validation scripts in ServiceNow platform. I need to validate form data on record producers and service catalog items. How do I properly validate form data on the server side without being called by a client script? I already have a catalog client script working to call a serverside ajax function in a script include.
What if the client is disabled? Then the server script is not invoked and the data goes in without validation. I learned in school that the best technique to validate forms when building web applications is to first validate on the client and then on the server. I have done this many times with javascript (client side) and PHP (server side). The PHP processes the validation on the server when it receives the user entry and does not need to be invoked directly by the client side. Client scripts can be disabled in the browser. This is why separate server-side validation should occur before the data is accepted.
How to achieve this in ServiceNow platform? I was thinking of using a Script Include called by a Business Rule.
Are there any simpler ways to complete this? Does anyone have any examples?
Upvotes: 0
Views: 1623
Reputation: 601
As another commenter said, data policies are the best way to do server-side validation of data before putting it into your tables.
I just wanted to add onto that, and say that if you have existing UI policies, you can usually click a 'related links' UI action to convert them to data policies. :-)
Upvotes: 1
Reputation: 551
It is a good idea to validate input on the server side and not just on the client side as you state. Using Business Rules to call Script Includes that contain your validation logic is a good way to accomplish this, however you may also want to consider using a feature called Data Policies in ServiceNow to accomplish this. Data Policies allow you to specify requirements for fields using a condition builder and allow you to specify when to apply these policies (i.e., from import sets, ui policies, web services, etc...)
Upvotes: 2