List attribute of Lookup field schema – Using URL versus GUID

There has been a lot of research about the List attribute of the XML schema of Lookup fields. In this post I will summarise their findings and add my 2cents about the pros and cons of each approach.

Some recommended readings on the issue:

http://pholpar.wordpress.com/2010/05/14/declaratively-adding-a-lookup-field-to-a-list-schema-using-the-name-of-the-referenced-list/

http://blogs.msdn.com/b/joshuag/archive/2008/03/14/add-sharepoint-lookup-column-declaratively-through-caml-xml.aspx

A summary of their findings:

  • The List attribute can be set to the web-relative URL of the source list, e.g. Lists/SourceList. This however only works when the Lookup field is being defined locally within the list schema like below.
<List xmlns:ows="Microsoft SharePoint" Title="SharePointProject7 - ChildList" ...>
 <MetaData>
 <ContentTypes>
 </ContentTypes>
 <Fields>
 <Field ID="{2EE02D6F-DFF1-417D-AED7-D139B9653D1F}"
 Type="Lookup" Name="MyField" DisplayName="MyField To Display"
 List="Lists/SourceList" ShowField="Title"/>
 </Fields>
 <Views>...</Views>
 <Forms>...</Forms>
 </MetaData>
</List>
  • Alternatively, the List attribute can be set to the GUID of the source list.

 

Pros and Cons

Pros of using the URL approach:

  • Simplicity: no additional coding is required

Cons of using the URL approach:

Pros of using the GUID approach:

  • Can create site columns
  • Can create cross-web Lookup fields

Cons of using the GUID approach:

  • Additional C# coding is required

My recommendation is to use the URL approach only for very simple scenarios where reusability is not a current or likely future requirement. Use the GUID approach for a more future-proof solution.

Advertisements

About Bernado

Based in Australia, I am a freelance SharePoint and Dynamics CRM developer. I love developing innovative solutions that address business and everyday problems. Feel free to contact me if you think I can help you with your SharePoint or CRM implementation.
This entry was posted in Lookup Columns, SharePoint, SharePoint 2010, Uncategorized. Bookmark the permalink.

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