Integer Field Formatting

amacqueen
Mega Guru

I modifying a module we created in Service Now and I've added two integer fields one of which I want to restrict to 2 characters and the other to four, additionally I want the four character field to display a 1234 and not 1,234.

 

Can anyone suggest an easy way to do this please as I can't track it down in the WIKI?

1 ACCEPTED SOLUTION

Hi Angus,



You don't need the number validation if you're using an integer field as the dictionary entry already validates that, so we only need to worry about the length. Here's an onchange script that returns an alert and clears out the value of the field if it's not 4 digits.



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


  if (isLoading || newValue == '') {


      return;


  }


  if (newValue.toString().length != 4) {


      alert("Please enter a 4 digit number");


      g_form.setValue('fieldname', '');


  }


}


View solution in original post

10 REPLIES 10

Thanks Harish for the help.



I have stuck with Brad's script as it cleared the field if I entered more than four digits.



Thanks anyway