PSA: Max length isn’t quite what you think it is

genericIn the vast majority of cases, setting the Max Length for a text field does exactly what you would expect… it prevents you or anyone else from entering a string longer than that specified max length.

But what happens when you decrease that max length value after the field has been in around for awhile?

Well, you’ll notice that any old values can stick around above and beyond the new shorter max length while CRM continually reminds you to fix them (if you happen to be on that record’s form).  So, there has been no actual truncation of data.  Behind the blue curtain the corresponding database field retains the old (larger) max length setting while CRM enforces the new (shorter) max length in the front end.  This might cause issues if you have integration packages, plugins, or other server-side components modifying that field since none of those technologies will be bound by the new (shorter) max length.

So… what to do?

Unfortunately, we can’t tinker with the DB field directly since this would be 100% unsupported.  The cleanest solution is to create a new field or drop and re-create your old field with the new shorter length.  This probably means you’ve also got some data to move around if you don’t want to lose what is already in the system so it’s bigger than a breadbox.  If that’s not in the cards then you could write a custom plugin to enforce the validation server-side.  Outside of that… you might just decide to live with it.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s