- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Overview
Although this feature has been there since Madrid, most of the developers I am in touch with keep validating forms in the old way, via scripts. Many don’t know yet about the possibility of using regular expressions and some other may be afraid of using them, but the reality is that once you are experienced with them, you will be developing faster and delivering more reliable solutions.
The best way to validate Service Catalog variables -that follow a pattern- is by using regular expressions and that is why ServiceNow released this fantastic feature two releases ago. This approach will requires less customisation and it is less likely to cause upgradeability, maintainability and performance issues.
Example: Validating telephone numbers
This used to be a tedious, yet frequent, case along with validating email addresses. It takes five minutes now to delivery a highly reliable and out of the box solution. Let's see how we can start taking advantage of it with an example.
In this example, we will create a “Variable Validation Regex” that will ensure the entered phone is following the British format
Note: Regular expressions need to be entered without the characteristic slashes that delimit them. This also means regex flags that should be specified after the last slash cannot be added at the end. However, regex flags can be used via the dropdown under the Regular Expression, although it is limited to “Case Insensitive”, “Unicode Case” or “Both”.
Once the “Variable Validation Regex” has been created, it can be used in our existing variables. In this case, we have a “Single Line Text” variable that keeps our Telephone number in a form.
If we click on the “Type Specifications” tab and select the regular expression we have just created in the “Validation Regex” field, then the platform will ensure that either the variable abides by it or the form cannot be sent.
When testing this feature, we will see the platform won’t allow any telephone that isn’t recognised by our regular expression.
On the other hand, any telephone that meets the criteria will be allowed.
For those who aren’t very experienced in Regular Expressions, I would recommend using online tools to learn, there are hundreds of options on the internet. Simply remember to test them in all possible scenarios, think in all the possible ways the end user is able to specify what you are requesting. Don't be overconfident, even regex experts need to validate them thoroughly.
Conclusion
ServiceNow have been using regular expressions for years, but during the last releases they are expanding the areas where these can be used to maximise efficiency and reduce issues.
Some examples of where these can be also used are: Edge Encryption to recognise strings that need to be encrypted using tokenisation, Discovery and Service mapping using them inside patterns to gather information from Configuration Items, in condition builders (UI Policies, Business Rules, etc…) by selecting the “Matches regex” operator or simply using them in scripts via the standard features offered by JavaScript to validate regular expressions.
If you haven’t learnt to use regular expressions yet, this seems like a great time to start practising and expanding your knowledge in ServiceNow!
- 2,611 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.