Microsoft SharePoint server tutorials: note fields have a maximum of 255 chars?

I posted a reply to this article in December, but have just been asked to extend upon my answer, so I thought I would post the reply herre as well for everyone else.

Microsoft sharepoint server tutorials: note fields have a maximum of 255 chars?


Original Post:
————————————————————————–
Submitted By: Ed Hild, e.magination
Posted On: 3/29/2004

Description:

SharePoint 2003 allows us to customize the metadata we would like to record for its libraries. Each metadata item is termed a column and when defining it, we get to specify the data type for the column. For simple text entries, we have the option of a single line of text (textbox) or multiple lines of text (textarea). Only for the single line of text do we get to specify a maximum length.

One would assume then that the multiple lines of text (Note) fields would be of an unlimited length. This hypothesis would be upheld by looking at the database structure since they map to ntext fields. However, entering a text of longer than 255 characters returns a javascript validation error when defining new items or editing existing ones. Unfortunately, this error is inconsistent as if you can go beyond this limit by coding against the API making for some interesting results.

The error seems to be in the ows.js file directly. You can see that a hardcoded limit of 255 is enforced there. Removing it seems to get rid of this made-up boundary. 

The ows.js file can be found at: C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS\1033. 

The function to modify is named: NoteFieldFValidateCore. You want to remove the second validation check that has the 255 limit in it.

if (fld.frm.wBaseType == 1 && field.value && field.value.length > 255)
{
fld.stError = StBuildParam(L_TextFieldMax_Text, fld.stDisplay, 255);
return false;
}

————————————————————————–

My intial reply was this:

Mark Stokes , 12/15/2005 
A bit late I know, but as you all know it is not recommended you change the default MS files, such as ows.js

All you need to do is copy the whole function into a new js file (I always call mine custom_ows.js) and in your site defs add an attribute to CustomJSUrl to point to this new file. Then remove the clause as mentioned in your orverridden function.

————————————————————————–

I received this reply by email:

Would you please clarify a few things for me?
– Where are the site defs defined?
– Where is CustomJSUrl defined?
– When you say, “remove the clause”, do you mean in the original ows.js file or the new custom_ows.js file?

————————————————————————–

Here is my longer repy:

Sure thing.

Site Definitions are the base templates that are used to create the configuration of a new WSS site. It is well worth reading up on the differences between Site Definitions and User Templates, paying particular attention to the issues with ghosting and unghosting. I leave that as a fun task for yourself!!

The Site Definition files are stored (under a default installation of SharePoint) in the following directory:
C:\program files\common files\microsoft shared\web server extensions\60\template\1033
You will see a bunch of folders called things like STS, SPS, MPS, SPSTOPIC, etc. Some might not be there if you don’t have portal server installed. Each of these folders stores a different site definition. It is comprised of a number of elements, such as an ONET.XML file, a whole load of list definitions created in CAML, and some other stuff.

One thing to note here is that adding the CustomJSUrl to a site definition now will NOT apply it to sites that are already created, only to sites that are created after you make the change. The only way to add it to currently created site is to add the attribute directly to the SQL database, but this is generally NOT a recommended or supported activity, so if you are going to try this, make sure you know what you are changing and test it on a dev box first!!

You add the CustomJSUrl attribute to the “Project” element of the ONET.XML file in the site definition you are changing. For WSS sites, I would imagine you want to be looking at the STS folder. The Project Element is the root element of the ONET.XML file. You can find lots of information on this in the SharePoint SDK. Go to microsoft.com and search for SharePoint Site Definitions, or SharePoint ONET.XML and a whole new world opens up to you!!

I normally store my custom JS files in the following folder:
C:\program files\common files\microsoft shared\web server extensions\60\template\layouts\1033\custom_ows.js

The value for the CustomJSUrl attribute in ONET.XML will then be “/_layouts/1033/custom_ows.js”. Another thing to note here is that this is assuming your SharePoint installation is using the layouts virtual directory from the default location. This can be check in IIS by looking at the home directory of the layouts virtual directory.

When I say “Remove the clause” I don’t mean change the original in ows.js at all. It is not generally accepted practice to edit any of the original SharePoint files. This is because in any update, patch or service pack, Microsoft could change any of these files and your customisations will be lost. What we do, is “override” the microsoft settings. In the same we we override the default look and feel with a Theme, or CustomCSS file, we can override the default ows.js file with our own custom js file.

So, override and remove the clause, look for the function in ows.js as mentioned in the original article, copy the whole function to your custom_ows.js file and remove the section that is referenced in the original article (from your custom js file)

Now, when you create a new site from this site definition you will no longer have this annoying 255 character limit on Note fields.

Hope this helps.

How to add Presence Information to your Custom Web parts

To add presence information to your custom webparts, you simply need to call the following javascript functionIMNRC() function, passing in the email address of the account you wish to check, such asIMNRC(‘info@sharepointstudio.com’)

This in turn calls a ActiveX control, name.dll, on the users computer.

My presence information:<br><span><img border=”0″ height=”12″ width=”12″ src=”/_layouts/images/blank.gif” onload=”IMNRC(‘themail@address.com’)” id=”IMID1″ ShowOfflinePawn=1> My Name</span>‚Äč

Leaving for a while

Hi everyone.

I know I have not been very good at keeping my blog up to date lately, but the day job has simply taken up so much of my time!

And I probably won’t be updating it for a very long time now, as in 4 weeks time I am flying out of the country, for a whole year back-packing around the world.

So, please don’t be offended if I don’t reply to any of your comments… I just won’t have seen them! If anyone else wants to reply to peoples questions then please feel free to.

I hope you all have a fantastic year, and good luck with MOSS 2007!