Fix Lookup Fields created through Features
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.
Call the method you just added and pass the temporary GUID you added in the Field XML.
Your lookup columns should be created automatically when the feature is activated and link to the correct lookup list.