Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Business Rule - for enforcing Max Length on a String Field

Elizabeth26
Tera Contributor

I need to set a string field to a max length of 13,000 characters. It currently does not enforce this.

I was thinking of doing this in a business rule - does anyone have any scripting/code for this?

I need something like this" You can create a business rule on the table with the field, to run on insert/update. and then truncate that field's value to the desired length. Defined the business rule to run "Before"."

 

 

7 REPLIES 7

samwallace881
Giga Expert

You could something like this:

var fieldName = current.<your_field_name>;

if(fieldName.length > 13000){

gs.addErrorMessage("Field cannot be longer than 13,000 characters");

current.setAbortAction(true);

}

 

OR instead of scripting you can just set that field's dictionary value to 13,000 for the max length attribute.find_real_file.png

I tried the code if it's not working not sure why? It doesn't like the "IF" statement which I did modify with my field name.

 

I have set the max length to 13,000 but it does NOT enforce anything that exceed 255 characters - it is a bug/feature from ServiceNow and this is what their support recommended. 

I got it working with some minor changes

var strFieldname = current.ait_fieldname.toString();
if(strFieldname.length > 13000) {
gs.addErrorMessage("field cannot be longer than 13,000 characters");
current.setAbortAction(true);
}

})(current, previous);

Jaspal Singh
Mega Patron

Hi Elizabeth,

 

I guess you need to set the field length to be 13000. If so, all you need is to right click the field select Configure Dictionary & update the field length.

 

Thanks,

Jaspal Singh

 

Hit Helpful or Correct on the impact of response.