Setting up a lookup field in the site deployer - Community forums - Akumina Community

Community forums

Forum Navigation
You need to log in to create posts and topics.

Setting up a lookup field in the site deployer

This is an example of a lookup to another list. First you need to create the list that has the data needed:

  <list name="FooterControlsList_AK" noCrawl="TRUE">

<Data>

<Rows>

<Row>

<Field Name="Title">RssNews</Field>

</Row>

<Row>

<Field Name="Title">Traffic</Field>

</Row>

<Row>

<Field Name="Title">Weather</Field>

</Row>

</Rows>

</Data>

</list>

 

Once that is in place, you can then create the list that has the lookup field:

 

 

  <list name="FooterControls_AK" noCrawl="TRUE">

<Field Name="ControlsList" ID="{bf54a5a7-b803-46b3-9160-ac5d27203a35}" DisplayName="ControlsList" Type="LookupMulti" ShowField="Title" List="{ReferenceListId:FooterControlsList_AK}" Mult="TRUE"/>

<Data>

<Rows>

<Row>

<Field Name="Title">Footer Control</Field>

<Field Name="ControlsList">1;#;#2;#;#3</Field>

</Row>

</Rows>

</Data>

</list>

 

A few notes:

The field definition

<Field Name="ControlsList" ID="{bf54a5a7-b803-46b3-9160-ac5d27203a35}" DisplayName="ControlsList" Type="LookupMulti" ShowField="Title" List="{ReferenceListId:FooterControlsList_AK}" Mult="TRUE"/>

The field definition uses a random GUID (ID="{bf54a5a7-b803-46b3-9160-ac5d27203a35}") - this is to denote if you need additional columns (example below).

The attribute List="{ReferenceListId:FooterControlsList_AK}" will resolve to the GUID for the list named "FooterControlsList_AK" so it is not needed to manually place that in.

 

Referencing the data

   <Field Name="ControlsList">1;#;#2;#;#3</Field>

The data field will reference the items by ID - so the order of the items in the referenced list is important. 1;#;#2;#;#3 in our example references the items with ID 1, 2 and 3 respectively.

 

Multiple field lookup

It is possible to do a multiple field lookup - this is where the Field ID becomes important. In the example given below (other portions omitted for brevity), we have a list  field that references the Languages_AK list with multiple columns, LanguageId and LanguageCode.

<Field Name="OrgLanguages" ID="{752ba44c-f6f7-43e6-80c5-8ddfd3b020fc}" DisplayName="OrgLanguages" Type="LookupMulti" ShowField="Title" List="{ReferenceListId:Languages_AK}" Mult="TRUE"/>
    <Field Type="LookupMulti" DisplayName="OrgLanguages:LanguageId" List="{ReferenceListId:Languages_AK}" ShowField="LanguageId" FieldRef="752ba44c-f6f7-43e6-80c5-8ddfd3b020fc" Mult="TRUE" Name="OrgLanguages_x003a_LanguageId" Version="1"/>
    <Field Type="LookupMulti" DisplayName="OrgLanguages:LanguageCode" List="{ReferenceListId:Languages_AK}" ShowField="LanguageCode" FieldRef="752ba44c-f6f7-43e6-80c5-8ddfd3b020fc" Mult="TRUE" Name="OrgLanguages_x003a_LanguageCo" Version="1"/>

Thanks Scott! I have a follow up question for you about this.

I was able to successfully deploy the lookup list, its associated content type and the list that uses a lookup column in a single deployment step.

I was not able to use a content type for the list that uses the lookup column however.  I attempted to use the RefereceListId:<listName> syntax in the content type field definition List attribute but that threw an error.   Something like "value in not in the expected format"...

I was able to get a content type to work for the list that uses the lookup column, however I had to use the id of the lookup list in the list attribute of the Field node in the content type xml.

        <Field Type="Lookup"
         Group="Custom"
         List="{bf8d8e3e-4c85-4595-ba9d-c436470d46a2}"
         ShowField="LookupFieldName"
         Name="FieldName"
         DisplayName="Field Name"
         Required="FALSE"
         ShowInEditForm="TRUE"
         ShowInNewForm="TRUE"/>
Having to use the list id means I cannot do this in a single deployment and I have to update the list id and do another deployment.
Is there another way to do this in one deployment using a content type?
Thanks,
Marc
//]]>