Lookup Fields and Custom Field Types

Image you want to display items in a dropdownlist in Sharepoint based on information from another list.
No problem, just use a lookup field. It works fine but there is one major drawback, the list needs to be already present on your site when you declare the lookup field.
This is tricky, because when you create a site definition (create onet.xml and al the stuff) you don’t have a list already present on any site.
Such a column needs to be presents in the columns gallery for reuse.
If you think, "what about the issuelist related issue column", this is also a lookup field. Yes, it’s true but it contains a reference to the list itself.
In all the out-of-box columns of microsoft you want find any example of a lookup field linked to a another list than itself.
Some blogs posts some solution for the problem (Chris O’Brien – Feature to create lookup fields on Codeplex) like modifying the internal Guid of the lookupfield which point to a non-existend list at the moment that you activate the field.
For some people this solution is good enough.
I thought to create a custom field type with my visual studio. very simple, their are only 3 parameters to configure on that field type: List, DisplayColumn, ValueColumn.
All parameters are string values. On the moment that the field actually is used, the field looks if a corresponding list is present on the current site with the name specified in the first parameter.
If the list is not present, you will have an empty dropdownlist, otherwise you will see all items of the list.
The DisplayColumn and ValueColumn is very usefull in the situation that your Title to display is not a primary key in the list (like the DataView class).
This entry was posted in Sharepoint. Bookmark the permalink.

2 Responses to Lookup Fields and Custom Field Types

  1. Tobias says:

    Is it possible to get your custom field?

  2. Tobias says:

    Of in het nederlands, is het mogelijk om dit doorgestuurd te krijgen? 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s