Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

limit single line text variable in RP form to 255 char

Amit Dey1
Tera Contributor

hi, we have a requirement to limit one Record producer text field variable chrarcter limit to 255 char , please help me in this issue.

 

 

Thanks in advance

7 REPLIES 7

Hi @Amit Dey1 

Let's try a simple OnChange Script.

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   if(newValue.length >= 255){
		g_form.showFieldMsg('short_description', 'Maximum 255 characters', 'error');
   }
   
}

 

Or you can simply define a help text in Annotation.

Screenshot 2023-10-25 at 15.32.15.png

 

Cheers,

Tai Vu

@Tai Vu @Amit Dey1 

 

The onChange script only works when the user moves out of the field.

I would go for an annotation to indicate the max amount.


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

@Amit Dey1 

for that you need onChange but as mentioned by Peter it would work only when user clicks somewhere outside the variable

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