I Want to set char limit to 250 char on multi Line text variable

Akki8219
Tera Contributor

I Want to set the character limit to 250 chars on multi-text variables but when I'm using max_length=250 in variable attribute it is not working

1 ACCEPTED SOLUTION

Service_RNow
Mega Sage

HI @Akki8219 

Try to this code

function onSubmit() {
	var maxLength = 290; // Add desired max length here
	var varName = 'full_description'; // Add variable name here
	var multi = g_form.getValue(varName);
	var len = multi.length;
	if(len > maxLength){
		var str = multi.slice(0, maxLength);
		g_form.setValue(varName, str);
		g_form.showFieldMsg(varName, 'Max length of ' + maxLength.toString() + ' exceeded for this field.', 'error');
                return false;
	}
}

Please mark reply as Helpful/Correct, if applicable. Thanks!

View solution in original post

8 REPLIES 8

Vishwa Pandya19
Mega Sage

Hello,

 

Please check below link:

https://docs.servicenow.com/bundle/washingtondc-servicenow-platform/page/product/service-catalog-man...

 

It clearly mentions that max_length is only applicable on single line text and wide single line text variable types.

VishwaPandya19_0-1713418784667.png

 

 

If my answer helped you in any way please mark it as correct or helpful.

So can you suggest me other way please

Hello,

 

You can try below client script:

 

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

   //Type appropriate comment here, and begin script below
   var text = newValue;
   var textlen = text.length;

   if(textlen >=250){
	g_form.showFieldMsg('your variable name','Your message exceeds 250 character length','error');
	g_form.clearValue('your variable name');
   }
}

 

 

If my answer helped you in any way please mark it as correct or helpful.

 

Not working