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 03:06 AM
Hi Sam,
Is it a integer field or string field since you are converting it into parseInt().
Why not use Regular expression for this?
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 03:10 AM
Hi Ankur,
It is an integer field. My understanding is all fields get seen as a string field and that is need to get it back to an integer?
Thanks
Sam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2017 03:18 AM
Hi Sam,
I think for number 1,000 the issue is coming up because of the comma. I think ServiceNow add comma if digit goes beyond 3.
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 04:00 AM
Is there a way to stop this?
Alternatively is there a way I can stop users adding more than 2 digits?