Pages

Monday, July 2, 2012

SharePoint 2010: Create a Content Type with Lookup Field by writing declarative XML

Create a content type with a lookup field in the Elements.xml file is not easy how you can think.

To accomplish this task you need to:

  • define the new field
  • specify Name, DisplayName, StaticName
  • set at TRUE the Overwrite attribute
  • set at ~sitecollection the WebId attribute
  • set at TheLookupList the List attribute
  • set at http://schemas.microsoft.com/sharepoint/v3 the SourceID attribute

for example:

<!-- CT Sotto Reparto -->
<Field ID="{2AAD1044-89E9-4C88-8234-424A4B739C1C}" Name="LookupToList" DisplayName="LookupToList" StaticName="LookupToList"
Type ="Lookup"
Required="TRUE"
Group="Custom Columns"
Overwrite="TRUE"
WebId="~sitecollection"
EnforceUniqueValues="FALSE"
List="Lists/MyList"
SourceID="http://schemas.microsoft.com/sharepoint/v3"
ShowField="MyLookupField" />


bye!

2 comments: