Monday 10 March 2014

SharePoint 2010 - Adding lookup additional columns for choice column type

SharePoint Lookup columns are great, and with SharePoint 2010 you can bring over additional columns from the lookup list. But these are limited to:

Single Line
Number
Currency

The "Choice" column type isn't supported. But we can use a combination of calculated columns and content types to get around this. The calculated column will take the Choice column and create a single line calculated column. The content type will "hide" this calculated column so it doesn't appear on forms. Note that this only works for Choice column types with single selection (multiple selections aren't supported)

So in this example, consider two lists

1. Countries

The list that will be looked up. Contains three columns - Name (single line), Continent (choice) and language (choice)

2. Offices

The list that will contain a lookup to Countries, and bring over Continent and language.

Steps

1. On the SharePoint site where the two lists are located.
2. Go to "Countries" list settings, Advanced Settings, "Allow management of content types"
3. On the "Contries" list settings, Create a new column called ":Continent" as a calulcated field. Use this formula

=IF(Continent="","",Continent)

This will stop "0" appearing if the Continent choice column has no value.
IMPORTANT: UNTICK "Add to all content types" and "Add to default view" before saving. This will stop this calculated column appearing in forms on this list.

4. Do the same (Step 3) for the Language choice column
5. Go to "Offices" list settings, Add a lookup column pointing to "Countries". You should now see the calculated columns (those with a ":" at the start for you to select). If you have normal single line columns you are bringing over, you can select these too. The difference is that the calulated columns have an additional ":" in their name. I.E.

Countries:Name, Countries::Continent, Countries::Language

It isn't too noticeable in the view ot form. And that's it!

No comments:

Post a Comment