Lookup and Choice column types serve similar purposes. Both provide choices from a list of values. With Choice columns, the values are entered directly in the column settings. With Lookup columns, the values come from another list.
Why go to the trouble of setting up a whole list just for a lookup? Because changes to the lookup list appear automatically in the Lookup column. To see how that works:
Select Charles Murphey as an assistant in the first row of the Phone List as shown in Figure 4-6, and then change his first name to Charley in the fifth row of the Phone List.
Click Actions -> Show in Standard View, and “Charley Murphey” now appears in the first row.
Finally, click on Charley Murphey in the first, and you’ll see his contact details. Lookups link lists together!
In this case, you’ve got to enter assistants before you enter managers (otherwise, you won’t be able to find their assistant). That’s always true of lookups: the source list must contain the values you want to look up before you can fill out the destination list.
Lookups can be used across any list or library in the current site. For example, you might add a Lookup column to a Task List that gets its values from a library containing Contracts. Each task then links to the contract that spells out the exact terms of the task as shown in Figure 4-7.
Figure 4-7.Using Lookup columns to drill down to a contract from a task list to a document
One thing you’ll notice when working with lookups is that you can’t look up values from a list in another site. Lookups can only get values from lists in the current site. To get values from another site, you need to create a site column.
SharePoint provides quite a few built-in site columns for general types of lookups. To add one of the built-in site columns to a list:
On the list toolbar, click Settings -> List Settings, and scroll to the end of the Columns list.
Click Add from existing site columns (it’s the second link after the end of the columns list). SharePoint displays the Add Columns from Site Columns page.
To add a site column to a list, select the column from the list on the left and click Add; then click OK. Figure 4-8 shows adding a Gender column to the Phone List.
Figure 4-8. Adding a site column to a list
The Gender site column is a simple choice column containing Male/Female options. The advantages of using a site column in this case are:
You don’t have to create your own Gender column each time you want to provide this choice.
The choice is consistent across sites: it’s always Male/Female, not M/F, or Yes/No (just kidding).
Most of the built-in site columns are simple text or date columns that include the name and description of the column. Exceptions to that rule are listed in Table 4-3.
Table 4-3. Special built-in site columns
Site column
Values
Append Only Comments
Multiline text: can only add text, not change or delete
Assigned To
Lookup from site users
Gender
Choice: Male/Female
Issue Status
Choice: Active/Resolved/Closed
Language
Choice from list of spoken languages
Priority
Choice: (1) High/(2) Normal/(3) Low
Related Issue
Lookup from Issues list
Status
Choice: Not Started/Draft/Reviewed/Scheduled/Published/Final/Expired
Task Status
Choice: Not Started/In Progress/Completed/Deferred/Waiting on someone else
UDC Purpose
Choice: Read Only/Write Only/Read Write
You can change the choices for most of these site columns—interestingly, you can’t change the Gender site column. For example, to simplify the Status choices:
Navigate to the top-level site in the site collection.
Click Site Actions -> Site Settings, and then click Site Columns under the Galleries heading in the middle of the page. (In MOSS, click Site Actions -> Site Settings -> Modify All Site Settings.)
Scroll to the bottom of the page and click the Status link just above the Core Task and Issue Columns heading. SharePoint displays the Change Site Column page.
Scroll down and delete the Scheduled and Published choices from the list under the Additional Columns Settings heading; then click OK. SharePoint changes the list of choices for all lists that use the column.
Removing choices from a site column doesn’t change the data in lists, it just changes the choices displayed when a user adds a new item to a list or edits an existing item.
Site columns share values across all of the sites within a site collection. They are set at the top-level site in the site collection, and those changes aren’t shared with other site collections.
You create new site columns to share values across all sites in a collection. A Department Lookup column makes a good example, since it’s best to have a single place to maintain the list of departments in case of a reorg. To create a Department site column complete these tasks:
Create a Departments list in the top-level site and add items to the list.
Delete the built-in Department site column. That column is a text column, so we’ll be replacing it with a Lookup column.
Create a new Department site column that looks up its values from the Departments list.
Add a new custom Department site column to the Phone List sample.
To create a top-level Departments list:
Navigate to the top-level site in the site collection.
Click Site Actions -> Create, and click Custom List under the Custom Lists heading. (In MOSS, click Site Actions -> View All Site Content -> Create.) SharePoint displays the Site Column Gallery page.
Name the list “Departments,” select No for “Display this list on the Quick Launch,” and click Create. SharePoint displays the new list.
Click Actions -> Edit in Datasheet and enter a list of your company’s departments.
To delete the built-in Department site column:
Click Site Actions -> Site Settings, and then click Site Columns under the Core Contact and Calendar Columns heading. (In MOSS, click Site Actions -> Site Settings -> Modify All Site Settings.) SharePoint displays the Change Site Column page.
Scroll to the bottom of the page and click Delete. SharePoint displays a warning. Click OK to delete the column.
To add the new custom Department column:
On the Site Column Gallery page, click Create. SharePoint displays the New Site Column page.
Complete the page as shown in Figure 4-9 and click OK. Name the column “Dept” as shown; we’ll change that next.
Click on the Dept column in the Site Column Gallery and change the name from Dept to Department; then click OK.
You can’t name the new column Department directly—that name is reserved by SharePoint. That’s why you have to name it Dept; then change that name to Department in step 3. That create-and-rename trick solves similar problems in other places, so please remember it!
Figure 4-9.Creating a custom site column using a lookup from the Departments table
To use the new Departments site column in the Phone List sample:
On the Phone List toolbar, click Settings -> List Settings, and click the Department column in the columns list.
Rename the Department column “Department Old” and click OK.
Scroll to the end of the Columns list and click “Add from existing site columns.”
Select the Department site column, click Add, and then click OK.
Display the Phone List and click Actions -> Edit in Datasheet.
Select the values in the Department Old column and drag them to the Department column. SharePoint moves the values from one column to the other.
After you move the values, you can delete the Department Old column from the Phone List and update the view used by the web part on the home page.
Please check back next week for the continuation of this article.