Limit for integer field

Sam Ogden
Tera Guru

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

18 REPLIES 18

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


Hi Sam,



alert(result); add this line after var result = validate.test(newVal);



Regards


Ankur


Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Added that, if I add values up to 99 I get:



find_real_file.png


and this for values over 99:


find_real_file.png


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


Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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