There has been a lot of research about the List attribute of the XML schema of Lookup fields. In this post I will summarise their findings and add my 2cents about the pros and cons of each approach.
Some recommended readings on the issue:
A summary of their findings:
- The List attribute can be set to the web-relative URL of the source list, e.g. Lists/SourceList. This however only works when the Lookup field is being defined locally within the list schema like below.
<List xmlns:ows="Microsoft SharePoint" Title="SharePointProject7 - ChildList" ...> <MetaData> <ContentTypes> </ContentTypes> <Fields> <Field ID="{2EE02D6F-DFF1-417D-AED7-D139B9653D1F}" Type="Lookup" Name="MyField" DisplayName="MyField To Display" List="Lists/SourceList" ShowField="Title"/> </Fields> <Views>...</Views> <Forms>...</Forms> </MetaData> </List>
- Alternatively, the List attribute can be set to the GUID of the source list.
Pros and Cons
Pros of using the URL approach:
- Simplicity: no additional coding is required
Cons of using the URL approach:
- No reusability: can’t create site columns using this approach
- Can’t create cross-web Lookup fields (i.e. the list using the Lookup field is not in the same subweb as the source list – but is in the same site collection. See this post for how to create these fields: https://bernado-nguyen-hoan.com/2011/02/09/how-to-create-cross-web-lookup-fields-through-xml-schema/).
Pros of using the GUID approach:
- Can create site columns
- Can create cross-web Lookup fields
Cons of using the GUID approach:
- Additional C# coding is required
My recommendation is to use the URL approach only for very simple scenarios where reusability is not a current or likely future requirement. Use the GUID approach for a more future-proof solution.