Second Life of a Hungarian SharePoint Geek

July 10, 2013

"Item cannot be more than 256 characters" warning at the PeopleEditor control

Filed under: SP 2010, Tips & Tricks — Tags: , — Peter Holpar @ 23:38

When working with the PeopleEditor control (either through a Person or Group field control on a list item edit form, or directly in a web part / application page) you might hit the limitation, that the control does not allow name resolution for strings longer than 256 characters. It is pretty annoying when you would like to copy a batch of user names from another application, like Word or Excel.

image

Based on the MS Knowledg Base article 2654222 it is a by design behavior. The proposed resolution:

You still can insert up to 200 users inside a SharePoint 2010 user control box. You just need to use the "Check Names" control in smaller batches.
For example, you insert a number of users that add up to less than 256 characters and click the "Check Names" control. You then add another batch of users and click "Check Names", and so on until you have added and resolved all of the desired users.

Although I’m understanding the reason of this limitation, I found the workaround everything but not user-friendly. Fortunately, there is a way to override this “feature”.

The limitation is regulated by the JavaScript variable g_MAX_LEN defined in entityeditor.js (debug version entityeditor.debug.js). When we inject the following script (either directly in the case of an application page, or through a CEWP / ScriptLink custom action in the case of an edit form) to the page, the limit is pushed up to 1000 characters. The change affects only the pages where the script block is injected. Of course, you should update the path to the jQuery script to match the location in your system.

<script src="/_layouts/jQuery/jquery-1.8.3.min.js"></script>
<script language="ecmascript" type="text/ecmascript">
function onPageLoad() {
 
g_MAX_LEN = 1000;
}
$(document).ready(onPageLoad);
</script>

The JavaScript variable (EntityEditor_ItemTooLong) of the corresponding error message is defined in a script block emitted by the RegisterScriptsAndVariables method of the EntityEditor class. If you would like to customize the message according to the new limit, you have to “override” the value of that variable as well.

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: