Over the last week, I was talking with my friend and fellow MVP, Sezai Komur, who pointed me to a valuable piece of code written by yet another of my friend, and fellow MVP, Tony Bierman.
The problem we are trying to solve is the ability to lookup columns across sites, within the same site collection. Tony has created an elegant way of doing that via a custom field type. I wanted to demonstrate an alternative out of the mechanism. The main difference between Tony's approach versus this approach is that Tony's approach will let you go either way .. i.e. .. a child site's list can be referenced in a parent site, whereas the illustrated approach below lets you go only downwards .. i.e. from root to child and grandchild .. or from child to grandchild. .. but the below is out of the box.
Problem statement:
I have a site collection at root, and a child site at \child. Root contains a list called “Animal Types”. And \child contains a list called “Zoo Animals”. I want “Zoo Animals” to have a lookup column that looks up values from the “Animal Types” list at root.
Solution:
(Before I start, all of this can be/should be done via features and solutions .. okay here goes.)
Step #1: Create the Animal Types list as shown below:
Step #2: In the root site (SPWeb) Create a content type called “Animal” that inherits from “Item”
Step #3: Add a site lookup column in the “Animal” content type, called “Animal Type”, which points to the “Animal Type” list you created in step #1.
Step #4: In the \Child site, create a list called “Zoo Animals”, and eliminate the “Item” content type, and instead add the “Animal Type” content type.
Step #5: That’s it. Now add a new animal .. .. and you should see the cross-site lookup work as shown below:
Now go ahead and add a new value in the “Animal Types” list .. called “Just plain weird”, and you will see that the new value shows up as well ..
Pretty cool huh? Okay I’m off to bed .. goodnight everyone!