- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2018 10:40 AM
I am trying to verify that a Service Catalog field entry is restricted to exactly a three digit value (i.e. 051, 789, etc). So I am trying to write a Catalog Client Script using Regular Expressions, but it is not working. I keep getting an error message that says "There is a JavaScript error in your browser console" in the Service Portal when I enter an invalid entry in that field, like "AAAAA".
I tried two different methods, but neither one worked. Here is the first:
Here is my second attempt, which is very similar to one we wrote for a Variable Set some time ago, but this one isn't working either.
Can anyone see what my issue is?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2018 11:12 AM
Thanks for the attempts. Playing around, we finally figured out something that works. We used this code to restrict it to numbers only:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var number = g_form.getValue('pbp_id');
if(!number.match(/^\d{3}/)){
alert('Please enter only a 3 digit number');
g_form.setValue('pbp_id','');
}
}
And then we used the following Variable Attributes to restrict the length,
max_length=3,min_length=3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2021 08:54 AM
This proved to be extremely helpful. Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2019 02:54 AM
jmiskey,
Depending on the version of ServiceNow, you can also define a regex variable instead of using onchange scripts...