Pre-populate ListFields on a SharePoint form

I needed to prepopulate a field in a SharePoint form with the value passed in from a QueryString. 

I needed to do this as i wanted to create a lookup to an item in another list, so I am passing in a QueryString value called PostID. This will be the ID of the item in the other list that I want to act as a lookup field.

Add the following code to the page header (on a page such as NewForm.aspx). I actually created a new page which contains the new item list form, so I put this code on that page.

<script language=”javascript” for=”window” event=”onload”>var elems = document.getElementsByTagName(“INPUT”);var PostID=””;var queryString =“&”);for (var i=0;i<queryString.length;i++) { if ((queryString[i].split(“=”)[0]==”PostID”) || (queryString[i].split(“=”)[0]==”?PostID”)) PostID=queryString[i].split(“=”)[1]; }for (var i=0;i<elems.length;i++) { if (elems[i].name==”OWS:Post:Local”) elems[i].value=PostID;}</script>

This looks for the QueryString value PostID and if it finds it, it search the INPUT items on the page for one calledPost and sets that form field to be the value passed in from the QueryString.

Post is the name of my List Column, so change that to whatever field you want to prepopulate. Also change the OWS:Post:Local bit to be the name of your column, so change Post to Title or whatever is appropriate. If you want to preset URL’s then you can use OWS:URL:URL and OWS:URL:DESC to set the 2 URL components.

The javascript could be tidied up a bit, you may notice that I search for PostID or ?PostID, this is because if PostID is the first QueryString item then it gets read with the ?. I just haven’t changed it yet.

I got the initial code for this from here: MSD2D and adapted it to my needs.

Document Library Template Selector

This great tip was devised by my on a previous contract. I needed a Document Library list template that had more than the normal 1 Document Template. I took the drop down code and changed the Add Document link to show a choice of document templates. I hope this is useful to others.
Template Selector


1. Implementing the Document Library Template Selector
1.1. Add Custom Document Template

  • Add the following documents to the DOCTEMP\Word folder of the Site
    • Business Case.doc
    • Communications Plan.doc
    • End Project Report.doc
    • Project Initiation Document.doc

1.2. Create New DocumentTemplate

  • Edit the Site Definiton Onet.XML File
    • At the bottom of the DocumentTemplates Element add the following:

<DocumentTemplate DisplayName=”Project Document Templates” Type=”1001″ Description=”A Collection of Templates for Project Manangement.”>   <DocumentTemplateFiles>       <DocumentTemplateFile Name=”doctemp\word\wdtmpl.doc” TargetName=”Forms/template.doc” Default=”TRUE”/>       <DocumentTemplateFile Name=”doctemp\word\BusinessCase.doc” TargetName=”Forms/Business Case.doc”/>       <DocumentTemplateFile Name=”doctemp\word\CommunicationPlan.doc” TargetName=”Forms/CommunicationPlan.doc” />       <DocumentTemplateFile Name=”doctemp\word\EndProjectReport.doc” TargetName=”Forms/EndProjectReport.doc” />       <DocumentTemplateFile Name=”doctemp\word\ProjectInitiationDocument.doc” TargetName=”Forms/ProjectInitiationDocument.doc” />   </DocumentTemplateFiles></DocumentTemplate> 

1.3. Create Project Document Library List Template

  • Copy DOCLIB List definition, call it PMDOCLIB

1.4. Customise Project Doc Lib Toolbar New Document links

    • Edit SCHEMA.XML
    • Remove the original Field Element and replace with: 

<Field Type=”Text” Name=”Title” ShowInNewForm=”TRUE” ShowInFileDlg=”TRUE” DisplayName=”Title” Sealed=”TRUE”></Field><Field Type=”Boolean” Name=”BusinessCase” ShowInNewForm=”TRUE” ShowInFileDlg=”TRUE” DisplayName=”Business Case” Sealed=”FALSE”><Default>0</Default></Field><Field Type=”Boolean” Name=”CommunicationPlan” ShowInNewForm=”TRUE” ShowInFileDlg=”TRUE” DisplayName=”Communication Plan” Sealed=”FALSE”><Default>0</Default></Field><Field Type=”Boolean” Name=”EndProjectReport” ShowInNewForm=”TRUE” ShowInFileDlg=”TRUE” DisplayName=”End Project Report” Sealed=”FALSE”><Default>0</Default></Field><Field Type=”Boolean” Name=”RequirementsMgt” ShowInNewForm=”TRUE” ShowInFileDlg=”TRUE” DisplayName=”Requirements Mgt” Sealed=”FALSE”><Default>0</Default></Field><Field Type=”Boolean” Name=”PID” ShowInNewForm=”TRUE” ShowInFileDlg=”TRUE” DisplayName=”PID” Sealed=”FALSE”><Default>0</Default></Field><Field Type=”Choice” Name=”Status” ShowInNewForm=”TRUE” ShowInFileDlg=”TRUE” DisplayName=”Status” Sealed=”FALSE”><CHOICES>  <CHOICE>Draft</CHOICE>  <CHOICE>Release</CHOICE>  <CHOICE>Archive</CHOICE></CHOICES><Default>Draft</Default></Field>

    • Rename the current definition of createNewDocument to createNewDocumentCustom
    • Change the createNewDocument function definition to be:

function ]]></HTML><GetVar Name=”WPQ”/><HTML><![CDATA[createNewDocument(){  createNewDocumentCustom(”)}

    • Change the line:

strTemplate = ]]></HTML>   <ScriptQuote><ListProperty Default=”Word.Document.8″ Select=”TemplateUrl”/></ScriptQuote><HTML><![CDATA[;

    • To:

var strTemplate;if(strTemplate != ”){  strTemplate = chosenTemplate}else{  strTemplate = ]]></HTML>  <ScriptQuote><ListProperty Default=”Word.Document.8″ Select=”TemplateUrl”/></ScriptQuote><HTML><![CDATA[;}

    • Change New Document toolbar cells to be: (change this for
      the 2 views, with DisplayName All Documents and Explorer View)

<td class=”ms-toolbar”> <table cellpadding=1 cellspacing=0 border=0> <tr> <td class=”ms-toolbar” nowrap><span class=’ms-SPLink’>  <span class=’ms-HoverCellInActive’ onmouseover=”this.className=’ms-HoverCellActive'”; onmouseout=”this.className=’ms-HoverCellInActive'”>      <a style=’cursor:hand’ title=”tooltip text” tabindex=”0″ accesskey=”\” id=”CustomMenuLink” onkeydown=”MSOMenu_KeyboardClick(this, 13, 40)” onclick=”MSOWebPartPage_OpenMenu(MSOMenu_CustomMenu, this);”>New Document <img align=”absbottom” src=”/_layouts/images/menudark.gif” alt=”tooltip text” /></a>  </span></span><span>   <menu id=”MSOMenu_CustomMenu” class=”ms-SrvMenuUI”>        <ie:menuitem onMenuClick=”javascript:]]></HTML><GetVar Name=”WPQ”/><HTML><![CDATA[createNewDocumentCustom(‘]]></HTML><ListUrlDir/><HTML><![CDATA[/Forms/BusinessCase.doc’, ‘]]></HTML><ListUrlDir/><HTML><![CDATA[‘)” type=”option”><img src=”/_layouts/images/icdoc.gif” ID=”tbbutton1N” alt=]]></HTML><HTML>”New Business Case”</HTML><HTML><![CDATA[ border=0 width=16 height=16> Business Case</ie:menuitem>        <ie:menuitem onMenuClick=”javascript:]]></HTML><GetVar Name=”WPQ”/><HTML><![CDATA[createNewDocumentCustom(‘]]></HTML><ListUrlDir/><HTML><![CDATA[/Forms/CommunicationPlan.doc’, ‘]]></HTML><ListUrlDir/><HTML><![CDATA[‘)” type=”option”><img src=”/_layouts/images/icdoc.gif” ID=”tbbutton1N” alt=]]></HTML><HTML>”New Communication Plan”</HTML><HTML><![CDATA[ border=0 width=16 height=16> Communication Plan</ie:menuitem>        <ie:menuitem onMenuClick=”javascript:]]></HTML><GetVar Name=”WPQ”/><HTML><![CDATA[createNewDocumentCustom(‘]]></HTML><ListUrlDir/><HTML><![CDATA[/Forms/EndProjectReport.doc’, ‘]]></HTML><ListUrlDir/><HTML><![CDATA[‘)” type=”option”><img src=”/_layouts/images/icdoc.gif” ID=”tbbutton1N” alt=]]></HTML><HTML>”New End Project Report”</HTML><HTML><![CDATA[ border=0 width=16 height=16> End Project Report</ie:menuitem>        <ie:menuitem onMenuClick=”javascript:]]></HTML><GetVar Name=”WPQ”/><HTML><![CDATA[createNewDocumentCustom(‘]]></HTML><ListUrlDir/><HTML><![CDATA[/Forms/ProjectInitiation.doc’, ‘]]></HTML><ListUrlDir/><HTML><![CDATA[‘)” type=”option”><img src=”/_layouts/images/icdoc.gif” ID=”tbbutton1N” alt=]]></HTML><HTML>”New Project Initiation Document”</HTML><HTML><![CDATA[ border=0 width=16 height=16> Project Initiation Document</ie:menuitem>        <ie:menuitem type=”separator” />        <ie:menuitem type=”label”>Blank Documents</ie:menuitem>        <ie:menuitem onMenuClick=”javascript:]]></HTML><GetVar Name=”WPQ”/><HTML><![CDATA[createNewDocumentCustom(‘]]></HTML><ListUrlDir/><HTML><![CDATA[/Forms/template.doc’, ‘]]></HTML><ListUrlDir/><HTML><![CDATA[‘)” type=”option”><img src=”/_layouts/images/icdoc.gif” ID=”tbbutton1N” alt=]]></HTML><HTML>”New Blank Word Document”</HTML><HTML><![CDATA[ border=0 width=16 height=16> Blank Word Document</ie:menuitem>   </menu></span>  </td> </tr></table></td>

1.5. Add Project Document Library List Definition to Site Definition

  • Change ONET.XML
    • Change the Name in the Project Element to Project Web Site
    • Add the following list definition:

<ListTemplate Name=”doclibproject” DisplayName=”Project Management Document Library” Type=”1051″ BaseType=”1″ OnQuickLaunch=”TRUE” SecurityBits=”11″ Description=”Create a document library when you have a collection of documents or other files that you want to share. Document libraries support features such as sub-folders, file versioning, and check-in/check-out.  This project management version includes multiple prince 2 templates.” Image=”/_layouts/images/itdl.gif” DocumentTemplate=”1099″></ListTemplate> 

    • Add the following DocumentTemplate item

<DocumentTemplate  DisplayName=”Project Document Templates” Type=”1099″ Description=”A Collection of Templates for Project Manangement.”>  <DocumentTemplateFiles>      <DocumentTemplateFile Name=”doctemp\word\wdtmpl.doc” TargetName=”Forms/template.doc” Default=”TRUE”/>      <DocumentTemplateFile Name=”doctemp\word\BusinessCase.doc” TargetName=”Forms/BusinessCase.doc”/>      <DocumentTemplateFile Name=”doctemp\word\CommunicationPlan.doc” TargetName=”Forms/CommunicationPlan.doc” />      <DocumentTemplateFile Name=”doctemp\word\EndProjectReport.doc” TargetName=”Forms/EndProjectReport.doc” />      <DocumentTemplateFile Name=”doctemp\word\ProjectInitiationDocument.doc” TargetName=”Forms/ProjectInitiationDocument.doc” />  </DocumentTemplateFiles></DocumentTemplate>

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


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 &&amp; 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 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(‘’)

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(‘’)” id=”IMID1″ ShowOfflinePawn=1> My Name</span>​