Limit for integer field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2017 02:29 AM
Hi all,
I've used the below on change client script to inform users to enter values between 1 and 25.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '')
return;
g_form.hideFieldMsg('u_risk_based_testing_score');
var newVal = parseInt(newValue);
if (newVal < 1 || newVal > 25) {
g_form.showFieldMsg('u_risk_based_testing_score', 'Values must be between 1 and 25', 'error');
}
}
If I enter values 1 - 25 these are fine. The error message then appears for values 26 - 999.
Then values 1,000 - 25,999 these do not show the error, then numbers 26,000 and above do.
Do you know what would cause this?
Alternatively is there a way to stop users adding more than 2 digits into the integer field?
What would I need to do to stop a user being able to save the form if they enter a value that is not between 1 and 25?
Thanks
Sam
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2017 06:36 AM
Hi Ankur,
Apologies, still getting used to scripting, what changes do I need to make to add the value for result in the alert?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2017 06:37 AM
Hi Sam,
alert(result); add this line after var result = validate.test(newVal);
Regards
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
11-20-2017 06:40 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2017 06:59 AM
Hi Sam,
So when it is true it won't go inside the if and won't show the field message.
whenever the value goes beyond 99 the field message will come.
this is what is expected right i.e. show the message if user enters value more than 2 digits.
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
11-20-2017 07:38 AM
Hi Ankur,
My requirement is that they can enter values between 1-25. The message shows up to 999. As soon as it goes from 1000 - 25,999 it is not working.
I was wondering if there is a way to actually stop them being able to put in more than 2 digits? so If they attempted to put 3 or more digits in it stopped them from typing after the 2nd digit and came up with a warning telling them it has to be between 1 and 25.
Currently if you enter 1000 - 25,999 the alert is returning true.
Thanks