- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2017 06:16 AM
I have an item in my Service Catalog that needs to have a single line text field that will only allow a numeric value and no less than 7 digits.
i am using the following client script which prompts a pop up box warning stating a number is needed for this field, but once you acknowledge the box, the system considers the field fulfilled even though there are still letters in the field as opposed to numbers. It will still let me submit the request with letters in that field.
Also, i am using the following variable attribute to allow only 7 digits in the field, is there a way to require at least seven as opposed to no more that 7?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2017 06:55 AM
Hi Katelyn,
If I have read your comment correctly then following is your requirement:
1) The field should have only digits
2) Also the length should be exactly 7 and not less than that and not more than that
If yes then following is the approach:
1) Have a onChange script on this variable and check whether it's a digit. you can use isNaN() method of javascript and if not clear the field
2) Second you have to check whether the length is exactly 7 so you can use length property on that variable
So here is your code
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// first check whether it is a digit
var fieldValue = value;
if(!isNaN(fieldValue)){
alert("This field should have only digits");
g_form.clearValue('field_name');
}
// now check the length
if(fieldValue.length != 7){
alert("Field should have exact 7 digits");
g_form.clearValue('field_name');
}
}
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2018 01:44 PM
Try moving your script from the variable set to the catalog item/record producer. Hope that works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2018 07:12 AM
Try moving your script from the variable set to the catalog item/record producer. Hope that works.
Unfortunately, that is not really feasible, as the Variable Set is used in 132 different Catalog Items!
However, the good news, we don't need to. We figured out the issue.
This line:
if(!isNaN(fieldValue)){
needs to be changed to this:
if(isNaN(fieldValue)==true){