When creating site columns through features you may have become stuck when it comes to Lookup columns. The Lookup field type is supported by the feature XML, however there is one catch. You must provide a unique GUID to the list that contains the lookup values. The problem is, we don’t know what the GUID to the lookup list is, as either we are creating it through features, or even if we get the GUID through the UI, it could easily change.
SharePoint 2010 has resolved this issue by allowing variables within the feature XML that will automatically add the correct list GUID when the feature is activated. However for SharePoint 2007 we need to provide a solution ourselves.
Create your feature as you normally would and be sure to include a feature receiver. In the Field XML, add a unique GUID for the List attribute and make note of it.
Group=”Custom Lookup Columns”
Add the following method to your feature receiver. This will replace the temporary GUID in the field schema with the actual GUID of the lookup list.
/// Fixes a site column lookup field added through a feature by replacing the temporary GUID in the feature to the actual list GUID.|
/// <param>The root web</param>
/// <param>The internal field name</param>
/// <param>The name of the lookup list</param>
/// <param>The temporary GUID that is added in the content type/site column feature XML</param>
private void FixLookupSiteColumn(SPWeb rootWeb, string fieldInternalName, string lookupListName, string tempGuid)
SPList lookupList = rootWeb.Lists[lookupListName];
SPFieldLookup field = (SPFieldLookup)rootWeb.Fields.GetFieldByInternalName(fieldInternalName);
field.SchemaXml = field.SchemaXml.Replace(tempGuid, lookupList.ID.ToString());
field.LookupWebId = rootWeb.ID;
Call the method you just added and pass the temporary GUID you added in the Field XML.
public override void FeatureActivated(SPFeatureReceiverProperties properties)
using (SPWeb web = (SPWeb)properties.Feature.Parent)
web.AllowUnsafeUpdates = true;
FixLookupSiteColumn(web, “Region”, “Regions”, “B5D4DCEE-61EB-4c53-9A9A-0BA2B81144F8”);}
web.AllowUnsafeUpdates = false;
Your lookup columns should be created automatically when the feature is activated and link to the correct lookup list.