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.
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.
Tip
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.
Tip
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!
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.
Figure 4-10 shows the updated Phone List web part that uses the new Department Lookup column to group the phone numbers. To see why I used a lookup site column in this sample rather than a choice site column, follow these steps:
Click on the Information Technology department link on the Phone List web part. SharePoint displays the item in the Departments list.
Click Edit Item and change the name to "IT," then click OK.
Go back to the Phone List web part and refresh the page. The Information Technology department is now shown as IT.
Not only that, but the name is updated throughout the site collection! In this case, the Department list functions as a master list for the site collection.
Lookups link lists together. Site columns span site boundaries. You combine them to create master lists. Master lists have these characteristics:
Exist at the top-level site in a site collection
Have a lookup site column
Hold values that need to be reused throughout the site collection
SharePoint does not have a way to create global master lists—lists can't span site collections. To reuse the master list in other site collections, you must copy the list to the other site collection and create a new site column in that collection.
Get Essential SharePoint 2007, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.