What is a list?
According to the SPS Admin guide, list is a collection of information that you share with team members. SharePoint has a set of built-in lists. You can customize these lists or even create your own lists. You can import an excel sheet in SharePoint to create a list automatically. The data in the newly created list will be extracted from the excel sheet. In document and form libraries, you can create custom columns or metadata properties and interestingly, you can autopopulate these columns with data that can be hardcoded or extracted from other lists that are part of the same site where your document library is located. This is a very common question. People ask me how they can populate a column with data from another list.
Recently, some one emailed me the following question:
I have a list of Projects in SharePoint called as "Projects" and list contains following columns:
1. Project Name
2. Project Manager
3. Status
I want to make another list called "Project Milestones" where one of the fields in this list would be the name of the Project from the "Projects" list.
Is there a way to have this be a drop down that points to the "Project Name" field from the "Projects" List?
Of course, yes! We can pull data from other lists to be displayed in our list.
Here is the answer to the question emailed by the user:
1. Add a new column in your "ProjectMilestones" list. This is the list where you want to show data from the other list. This can a document library or a form library, depending on your needs.
2. Name the new column as "ProjectName".
3. Column type should be "Lookup"
4. In the "Get Information From:" drop down under "Optional Settings for
Column", select "Projects" list.
5. In "In this column" drop down, select "Project Name".
6. Click OK.
This newly added field will display project names from the "Projects" list.
Let's talk about the lookup field a bit. Lookup field refers to values from a field in another list as you saw above. It's a great way of linking two lists together. You can easily pull column values from different lists already available in your site. If you are a programmer like me, then you may want to look at the way how we can add a lookup field to the form programmatically. Here is the code:
SPSite site = SPControl.GetContextSite(Context);
SPFieldCollection fields = site.AllWebs["mysite"].Lists["mylist"].Fields;
SPList lookupList = site.AllWebs["mysite"].Lists["mylookuplist"];
Guid lkListID = lookupList.ID;
fields.AddLookup("Lookup_FieldName", lkListID, true);
If you work regularly with SharePoint, then you will find this tip to be very helpful.