Server side validation without being called by client scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2015 07:22 AM
I am writing validation scripts in ServiceNow platform. 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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2015 10:43 AM
Hi Leslie,
For server side validation, using business rule is good. If you can write a reusable code then use script include otherwise write the code in a function in business rule itself.
Hope this will help and confirm you on your strategy.
Thanks
Himanshu Singhal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2015 02:57 AM
Hi Leslie,
Turned off Scripting on browser sounds strange, related ServiceNow, Java scripts is used a lot, and there are a lot of scripts generated automatically, but in any way Busines Rule should help you with validation task. They will fit perfectly with Script Include. You can call the same code both, from client side(using AJAX) and from Business Rules.
More then, there is a recommendation to have both of them. Data can be inserted using varuius ways, not only from client side, and server side code will be able to validate it.
Please see:
Business Rules Best Practices - ServiceNow Wiki "Use Business Rules to Double-Check Critical Input"
Aslo Data Policy can be used for some types of validation:
Thanks,
Hope it will be useful.