Script to limit max size of string field.

Ian46
Tera Contributor

Hi,

I have many string fields set to 400 characters. This allows the boxes to be the right size. However I need to stop users putting in too much data. How best to do this with a script?

I tried an On Change Client script, but it didn't work:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') 
   {
      return;
   }
   if(newValue.length>4000) 
   {
      g_form.showErrorBox("your_field","You cannot enter more than 4000 characters",true);
   }
}

 

Can anyone suggest the best way to achieve this?

Thanks Ian

14 REPLIES 14

Anurag Tripathi
Mega Patron
Mega Patron

Check this link, this is probably the solution you want. OOB and no code solution

Enable the text field character counter

 

find_real_file.png

 

 

-Anurag

-Anurag

Thanks that's good to know. Typically it doesn't work in SP though, so that isn't going to work for this case unfortunatley, as far as I can see.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

So the maximum length should be 4000.

Did you try to give alert in the client script

Regards
Ankur

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

I tried but failed, I am using it in SP if that makes a difference?