Is there any solid (proven) method of creating Site columns (lookups) where list GUID is not known?
I think this is where feature activation kicks in; getting the lookup list by its name and then using the GUID to create the lookup.
Is there any solid (proven) method of creating Site columns (lookups) where list GUID is not known?
I think this is where feature activation kicks in; getting the lookup list by its name and then using the GUID to create the lookup.
Isn't too difficult really, in the FeatureActivated method, you just create a new SPieldLookup (using SPWeb.Fields.AddLookup() for the SPSite's RootWeb), and set the properties for the SPFieldLookup as required.
First time doing it? Bit tricky if you've never made a FeatureReceiver before, let me know if you need a tutorial do that, and here's some sample code that should get you started (this will create a field that matches to "Title" of "My List") [also, this needs to be a FeatureReceiver for a Site Collection -scoped Feature];
SPWeb oWeb = ((SPSite)Feature.Parent).OpenWeb();
SPList oList = oWeb.Lists["My List"];
oWeb.Fields.AddLookup("My Lookup Column", oList.Id, false);
SPFieldLookup lkp = (SPFieldLookup)oWeb.Fields["my Lookup Column"];
lkp.LookupField = "Title";
lkp.Update();
Take a look at this article:
Declaratively adding a lookup field to a list schema using the name of the referenced list