onChange Validation Script against Catalog Item Variable - HELP!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2013 12:48 AM
Hi there,
I'm fairly new at using ServiceNow and I have a little bit of experience with JavaScript but I'm shaky with the ServiceNow API.
I am trying to put together a Service Catalog client script that validates on a variable (single line text field) so that users are only able to input numeric characters in this particular input.
I've tried a number of different scripts but I've not had much luck - after speaking to someone at ServiceNow they suggested that I look at some of the Validation Scripts in ServiceNow (System Definition > Validation Scripts). I had a look at the numeric script and tried this in my Service Catalog client script but it didn't work. After reviewing the code and carrying out some more research I can see that these scripts aren't using the GlideForm API and I believe this is where it is going wrong.
Has anybody else used Service Catalog Client Scripts to cover a similar scenario and if so please can you shine some light as to how you did it?
Many thanks 🙂
Jamie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2013 07:33 AM
You can write the onChange client script on the field.Copy below code :
****************************************************************
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '')
{
return;
}
if (newValue.match(/^\d+$/))
{
return true;
}
else
{
alert('Please enter only numeric value');
}
}
****************************************************************
Thanks,
ND
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2013 04:38 AM
Hi there,
Thanks for this, I've tested the script and it works like a dream!
Once again, can't thank you enough!
Jamie

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2015 12:14 PM
Sorry to resurrect this old thread, but this is exactly what I'm needing too. Where do I paste in the script though? I see no place to put javascript for this "single line text" variable.
**UPDATE**
Okay, I found that I needed to add a new "Catalog Client Script", and paste that code there. However, is there any way to make this an "onkeyup" event ? Perhaps onCellEdit?
I try the onCellEdit, and a simple alert() won't even pop up:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2015 01:37 PM
Usually you want an "onChange" script.