Quantcast
Viewing latest article 18
Browse Latest Browse All 25

SharePoint List Template with Lookup Fields

If one creates a list template that has a lookup field to another list (the reference list), and then attempts to create a new list from that STP template in another site, the data in the lookup field of the new list will be empty. Of course the obvious reason is that the reference list does not exist in the new site.

The problem is that even if you create the reference list (or import it with another list template) in the new site, that won't simply work because the lookup field defined in the STP file refers to a list through a GUID that is valid only on the site from which the STP template was originally created.

Even though I created a list with the same name, it has a different GUID.

The solution to this is:

0-Import reference list to the new site, and note its new GUID. Open the STP file and replace the GUID of the original reference list with the GUID you just noted, this is how you can do that:

1-STP files are CAB files: so you can rename the template file's extension to be able to open it as a CAB file. You can verify this by openning the STP/CAB file and finding that it is a BINARY file that starts with the letters MSCF (Microsoft CAB Format).

2-Extract the Manifest.xml file from the CAB and open it in an XML editor. This is a big XML file, so I rather open it in an XML editor e.g. Visual Studio. Note that even you open it in an XML editor, it is not pretty formatted by default.

3-Find the definition of the lookup field. It will be something like the following. I have a Multi lookup field, so the lookup field type says LookupMulti. I found this field by searching for the GUID of the original reference list as you can find in the List attribute. I then replaced it with the correct GUID that applies to the site to which I'm importing my list with the lookup field to.

<Field Type="LookupMulti" DisplayName="RequiredTrainings" Description="The trainings required for the corresponding job title." Required="FALSE" EnforceUniqueValues="FALSE" List="{ddfd206e-206a-405b-8926-94447e2c3d09}" ShowField="Title" Mult="TRUE" Sortable="FALSE" UnlimitedLengthInDocumentLibrary="FALSE" RelationshipDeleteBehavior="None" ID="{165f9634-9a76-4c4f-b1f0-9b1e09e9f2ed}" SourceID="{56091bc8-c44c-438c-a114-18e283cd3ca4}" StaticName="RequiredTrainings" Name="RequiredTrainings" ColName="int1" RowOrdinal="0"/>

4-Recreate the CAB file. You can use makecab DOS command.

5-Rename the cab to STP and import it to the site, then create a new list from it!

Viewing latest article 18
Browse Latest Browse All 25

Trending Articles