
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2016 04:37 AM
Good morning all,
I have two things that I am trying to solve for:
1. I am trying to set one of my catalog variable to a max length of 9. I've done this for other variables but it seems for some reason that it is not holding the max_length=9. Even though I change the view to get to the variable attributes and I save it after I've entered the max length, the system is not holding what I've put in.
2. Also is there a way to make that same variable ONLY 9 characters. Meaning the customer doesn't want any less than 9 characters or any more than 9 characters.
Thank you,
Karen
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2016 04:43 AM
- Try and add variable attributes as a column in the variables table on the parent catalog item and change the value through the table
- You have to enforce the 9 characters via an onChange / onSubmit client script where you display some sort of error if anything less than 9 character have been entered
E.g. an onSubmit CS:
var routing = g_form.getValue('dd_routing_number1');
if (routing.length != 9) {
alert('You must enter 9 characters');
return false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2016 04:45 AM
You can use below:
if (current.variables.urfield_id.toString().length != 9) {
g_form.addErrorMessage('max length should be 9');
}
Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.
Thanks,
Deepa

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2016 04:46 AM
According to the wiki, it should work.
See section 21 here. Variable Types - ServiceNow Wiki
Have you tried other values?
If you want to ensure you have 9 and only 9 characters, An onSubmit client script could do a quick character count and abort. Something like:
function onSubmit(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (current.newValue.length != 9) {
g_form.addErrorMessage('9 characters only please.')
return false;
}
}
This script is untested.
http://wiki.servicenow.com/index.php?title=Client_Scripts

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2019 04:47 AM
Very lame that this happens. It's absurd that you can't set max_length, and that you'd need to rely on an onSubmit script to handle it.
So, I personally get the maxlength attribute set by manipulating the DOM via an SP widget:
I have a Single Line Text field named "upc" as a Catalog Item Variable.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2019 08:00 AM