12 02 2009
Creating cross-site lookup field in SharePoint
Cross-site lookup field is something we need almost every project that is not very small. There is no good OOTB solution but we can use field by Toby Bierman. This kind of field is easy to create because SPFieldLookup is cross-site by its nature. Basically you ave to perform the following steps.
- Create custom field that extends SPFieldLookup.
- Create editor control for this form. This form may look exactly like Lookup fields one but you have to add dropdown for site selection.
- Write logic for filling dropdowns when something is selected from webs or lists dropdown.
- Override field saving method and assign value to LookupWebId property of lookup field.
LookupWebId property is already there but SharePoint doesn’t show us it through user interface.
Although it may seem to be convenient to use and extend SharePoint’s own lookup field UI control you shouldn’t do it – it is currently for internal use only and if something changes then you nobody warns you. LookupWebId property is public property and when something changes then users should be warned before.