Wednesday, 15 June 2011

SharePoint 2010 - Lookup Field + Content Type

A useful feature within SharePoint is the Lookup field.  This allows you to retrieve information from one list and display it as drop down list within another field.

Within SharePoint 2010 you can also pull through additional information about the field selected within the lookup dropdown.

Content Type

Within the content type declare the field reference for the Lookup.  Also declare an additional field references for the extra information you want to retrieve for the other list.

<FieldRef ID="{5955A1CD-3EF5-4D58-9DA6-628D0C997CD2}" Name="Employee" />
<FieldRef ID="{8BFAD894-D22C-4AED-91A2-2A75732899EC}" Name="EmployeeID" />


Within the schema for the content type you need to identify the list that the information is going to be retrieved from and the fields that you wish to display.

<Field ID="{5955A1CD-3EF5-4D58-9DA6-628D0C997CD2}" Type="Lookup" DisplayName="Employee" List="Lists/EmployeeDetails" ShowField="FullName" Name="Employee"/>
<Field ID="{8BFAD894-D22C-4AED-91A2-2A75732899EC}" Type="Lookup" DisplayName="ClockNo"List="Lists/EmployeeDetails" ShowField="ID" FieldRef="5955A1CD-3EF5-4D58-9DA6-628D0C997CD2" Name="EmployeeID" />

Key Items


The type attribute determines the SharePoint field type.  For other field type see table bellow.

SharePoint Field


Addition Info

Single Line of Text Text  
Multiple Lines of Text Note  
Date and Time DateTime Use Format tag to determine within is DateOnly or full DateTime
Choice Choice Use Format tag to determine display type: Dropdown, RadioButtons
Lookup Lookup  


The List attribute is used within a lookup field to determine which list the information is going to come from.  You can also specify the unique Guid for the list in here but be aware that it will change each time a list is deployed.


The ShowField attribute is used within a lookup field to determine which pieces of information are to be retrieved for the specified list.


Within any Lookups fields that have been created to pull back additional information you need to reference the main lookup field.  I have found that this works best if you omit any curly brackets from this reference.

No comments:

Post a Comment