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.

To limit Short description length to 80 characters

Gopi22
Tera 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

8 REPLIES 8

Rajender1
Mega Sage
Mega Sage

Hi use below code and it  will solve your question 

function onSubmit() {


//Type appropriate comment here, and begin script below


var shDesc = g_form.getValue('short_description');


if(shDesc.length > 100){


alert("Your short description should be 100 characters or less. Please correct.");}


return false;


}

plz mark correct and helpful if it clarify your question 

Thanks 

Rajender

Darshani Sambar
Giga Contributor

Hi,

 

 

Business Rule

 

Condition: current.getValue("short_description").length > 80

 

Script:

 

current.abortAction(true);

 

gs.addErrorMessage("The short description field can be no more than 80 characters")

 

 

 

Client Script

 

Type: onChange

 

Script:

 

var value= g_form.getValue("short_description");

 

if (value.length > 80) {

 

g_form.showFieldMsg("short_description", "The short description field can be no more than 80 characters", "error");

 

g_form.setValue("short_description", value.substring(0,79));

 

}

 

please mark as correct/helpful based on impact.

 

Thanks

Darshani Sambare

Hi,

this is another way to give a length,

go to form design and set a "max length=80"

find_real_file.png

Thanks

Darshani

Darshani Sambar
Giga Contributor

Hi,

This is another way to set a length,

go to form design and set "max length=80"

 

Thanks

Darshani