
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
01-10-2021 10:13 PM - edited 08-16-2024 10:36 PM
Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
What is shared in this article, might not be best practice. Just sharing this to explore possibilities, find openings in ServiceNow, and have a mindset that your imagination is your limitation. |
Hi there,
When designing Virtual Agent topics, a subject to keep in mind is error handling. For example, if User Inputs are not valid for your Topic. With the Paris-release, ServiceNow added Text Input format validation. A great enhancement, at least User Input Text can now be validated without having to add additional steps to your Topic design!
Though what if, you would like to set up your own Input Validators?
Text input format validation
From the Docs:
"In the Text input control, use the Text Input Format field to specify a text format that is validated when a user enters: email addresses, phone numbers, IP addresses, and URLs. You can also specify a custom text validation, which uses a script to set validation rules and related error messages."
The usage of User input text validators is really basic. On any User Input Text, in the User Input Properties (upper part of the right side column), click the Text Input Format field. This will present you with:
Out-of-the-box Text, Email, IP Address, Phone Number, and URL are available as validators. You can also add your own Custom validator on each User Input Text.
Custom validator
On the introduction of the Text input format validation, I quickly started using it, and especially the Custom validator option. Though also quickly asking myself… what can I do to limit myself from doing Custom validators over and over, on several steps in a Topic, in several different Topics. Referencing a function in a Script Include would help already. Though, let's dig a bit further… where do the out-of-the-box Validators come from? Are these embedded in the $conversation-builder page and therefore untouchable, or might these be stored somewhere?
sys_cs_field_script_validator
It took a bit of a search, it's undocumented, though… table sys_cs_field_script_validator is what we are really after! This table holds the out-of-the-box Validators.
Looking at the code, the out-of-the-box Validators do use Script Include "VAFieldValidator". You would expand that Script Include, or only use the validator script field. For this article, I just make use of the validator script field.
Integer
There's no Integer Validator. So let's set up a custom one. Looking at the out-of-the-box Validators, the validator script should return a true or false value. If false, the Error Message will be triggered.
Regex to validate an Integer could already be something like:
^\d*$
Translating this into the validator script:
function validate(value) {
var answer = false;
if(value.match(/^\d*$/g)) {
answer = true;
}
return answer;
}
And that's it!
Result
After adding the new Conversation Server Field Script Validators record, Integer is available as Tekst Input Format:
Triggering this new validator in a Virtual Agent chat would result in:
Instead of using the custom option over and over, on several steps in a Topic, in several different Topics, we now have our own custom validator available as a selectable option!
---
C |
If this content helped you, I would appreciate it if you hit bookmark or mark it as helpful.
Interested in more Articles, Blogs, Videos, Podcasts, Share projects I shared/participated in? |
Kind regards,
Mark Roethof
ServiceNow Technical Platform Architect @ Quint Technology
1x ServiceNow Developer MVP
1x ServiceNow Community MVP
---
- 3,922 Views

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Great work, Mark. I have submitted an enhancement request on the Idea Portal. Give it an upvote to gain some traction 🙂
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Awesome post Mark, thanks for taking the time.
Why there isn't an integer or alpha check OOTB is anyone guess.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
This is really useful thank you!
I see that creating records in the sys_cs_field_script_validator table (now?) seems to require the maint role. Obviously there are ways around this, but I wonder if there's a good reason why ServiceNow seem to have tried to limit this.
I can't see any reason why adding another field validation would be a bad thing (assuming the script is efficient and sensible).

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@G_Ede interesting comment! I will look into it, didn't knew that it's maint role now (not working on Virtual Agent a lot the past 1,5 year anymore), or that its perhaps already since 2 or 3 releases. Can't immediately think of reason why this would be. Obviously it's no big issue, since we can just admin override or add the admin role ourselves 🤣 though not every customer might like that or perhaps ServiceNow does have a serious good reason for doing this and we just not knowing it yet.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@Mark Roethof Thanks! My thinking is along the same lines! We can get around it, but I have also raised a HI case to ask if there's any reason we are missing that perhaps suggests we shouldn't... 😅
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@G_Ede Did you end up getting an answer from your HI case as to why creating records in the sys_cs_field_script_validator table is locked down to the maint role? We are also looking into adding another field validator.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@LShetler this was the response we got, effectively "proceed at your own risk" but no detail on why it was restricted as such:
"In order to have custom field validators, they need to be created using the Variable Validation Regex and once created they need to be applied to Question/Variable if they are to be applied directly. In order to apply the validators to a field, an onChange script is required for the particular field to make the validation functional.
Since this is a customisation, unfortunately this is out of scope for the UX-Support Team. However, a couple of community articles that might help achieve this customisation are as follows :
https://www.servicenow.com/community/hrsd-forum/hh-mm-ss-format-for-string-field/m-p/1331253
(Regex for hh:ss:mm validation)
(creating a custom field validation)
Hope that helps! I don't see any reason why a well-written validator script would cause a problem personally.