- 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
‎04-21-2017 08:05 AM
i was able to like the post, but i do not see an action to mark it as the correct answer on my page. I have seen this before, but for some reason do not see it now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2017 08:14 AM
Your post was not originally marked as a question, only questions have answers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2017 08:18 AM
Ah. Thank you, Chris!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2018 02:11 PM
I believe dan.bruhn can switch it to a question for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2018 01:10 PM
I pretty much have the same scenario. We have a Single Line Text variable on our form that MUST be exactly 6 numbers. So I tried incorporating this variable script, but cannot get it to work. I get a JavaScript error, and then it accepts any entry I make.
Here is my script:
The only difference it is running against a Variable Set, but that shouldn't matter, should it?
Here is the error message I get:
"There is a JavaScript error in your browser console", and then it accepts the entry, even though it doesn't meet the criteria.
Any idea why this isn't working?