To limit Short description length to 80 characters

Gopi22
Giga Guru

Hi,

 

I have got a requirement wherein the short description field in Incident form should be limited to 80 characters.  

User who is typing should be able to type only 80 characters and when he/she types the 81st character, an error message should be displayed and not allow to type more.

Please help me with this. Thanks in advance!!!

 

Regards,

Gopi

1 ACCEPTED SOLUTION

Shishir Srivast
Mega Sage

I think, it has to be with onChange() client script, when user enters the value and move out of the field then it can display a message and also, we can set the length of the field to 80



  1. if (newValue.toString().length > 80) {
  2.       g_form.setValue('short_description', newValue.substring(0,79));
  3.       alert('Please enter 80 or less characters.');  
  4. }  

View solution in original post

8 REPLIES 8

Shishir Srivast
Mega Sage

I think, it has to be with onChange() client script, when user enters the value and move out of the field then it can display a message and also, we can set the length of the field to 80



  1. if (newValue.toString().length > 80) {
  2.       g_form.setValue('short_description', newValue.substring(0,79));
  3.       alert('Please enter 80 or less characters.');  
  4. }  

Thanks Shishir....this worked for me



Thanks a lot!!!


Thank you Gopi,



Please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list. https://community.servicenow.com/docs/DOC-5601


jarodm
Mega Guru

I've seen on previous customer instances (I don't have the code anymore) where an onChange Client Script calculated the length of the field, and if it was greater than 80 chars, it would trim it back to the first 80.



Note: This won't work when editing the short_description in List View.



Jarod