RSS
Add to Technorati Favorites
Follow me on Twitter


Becky Bertram's Blog > Posts > Declaratively Referencing a Lookup List in a Lookup Column in SharePoint 2010
Declaratively Referencing a Lookup List in a Lookup Column in SharePoint 2010
One of the ugly things that most of us developers had to deal with in SharePoint 2007 was that a Lookup column could not point to the name of a list that it was referencing; it had to point to the GUID of that list. That could be quite problematic. If you had one feature that provisioned a new list called "My List", then each time that feature fired, that list would have a different GUID. If that was the case (which it often was) you couldn't hard code a referencing list GUID into your Lookup field definition since you didn't know what that GUID was yet, if your field feature fired after the list provisioning feature.
 
Luckily, in SharePoint 2010, you can now declaratively specify the name of the list you want your list to reference. For instance, having the following Elements.xml file will provision a site column that references the "Title" field of the "Documents" library.

<
Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<
Field Type="Lookup"
  
SourceID=http://schemas.microsoft.com/sharepoint/v4
  List
="Documents"
  
Name="DocumentsLookup"
 
DisplayName="Document Title"
 
StaticName="DocumentsLookup"
 
Group="Custom Columns"
 
ShowField="Title"
 
ID="{D7C4EAC7-DB92-4acf-8DF5-B5E018578DED}"/>
</Elements>

Comments

Fantastic!

This is great news.  I really struggled with this on a project and going forward it is nice to know that his is now a viable option.  Thank-you.

in the nick of time

Thanks Becky, I am deploying a new site to our new business development group and this is exactly what I need to do. The most problematic thing I had to do was explain to them why SharePoint acted this way. They wanted it to act like a relational database....sheesh!

Still seeing the same issue in 2010

I have tried using this method in a new 2010 site and I am still running into the same old issue as in 2007. Has anyone tried this a number of times and got t to work reliably?

More Info

John H, could you provide more info about the errors you're receiving? I got some errors too, initially, and then all of a sudden it started working for me. (Gotta love those kind of errors!) Are you deploying the referenced list as a feature? Is the referenced list in the same Web as the lookup column?

RE: More Info

Hi Becky. Yes, I am deploying the referenced list as a feature. The list and columns features are hidden and are activated by a parent provisioning feature with activation dependencies.

So, in site collection features, the parent feature is available. Activate this and the list feature is activated first, followed by the column feature. The list is deployed successfully and the columns are all present except that the lookup columns' bindings are not present :(

In the end, I had to opt for using a feature receiver to ensure the lookup binding was correct

How it works in WSS 3.0

You can achieve similar results using WSS 3.0 as well. See this post about the "how to":
http://pholpar.wordpress.com/2010/05/14/declaratively-adding-a-lookup-field-to-a-list-schema-using-the-name-of-the-referenced-list/
 

Comment Title *


Your Name


Body *


Your E-mail Address


Your Website

Type the Web address: (Click here to test)  

Type the description: 

Post Date *

Post Title *