How to create cross-web Lookup fields through XML schema

By “cross-web” Lookup fields, I mean a Lookup fields that refers to a source list that is in a different subweb than where it is currently being used. So ListA has a Lookup field that points to ListB. ListB however is not in the same web as ListA, but is in the same site collection.

You can’t create these cross-web Lookup fields through the SharePoint UI, but you can through the XML schema. To do this, set the List attribute to the GUID of the source list, and the WebId to the GUID of the web containing the source list, for example:

<Field Type="Lookup" Name="MyLookupField" DisplayName="My Lookup Field" Group="Custom Columns"
		   ID="{4F519ADB-037E-4405-AA00-AD0B001DFB88}"
		   List="{84ad635d-73e6-4775-b729-90731ba22f2a}"
		   WebId="{7d1f9cad-c7ce-4992-bfce-6d517e45db16}"
		   ShowField="Title"/>

The WebId attribute is not very well documented.

You are probably asking how can I know what the GUIDs are when crafting the XML?? Well.. you can’t. Check this post for a solution: http://www.sharepointnutsandbolts.com/2007/04/creating-list-based-site-columns-as.html.

IMPORTANT: Make sure the GUID for the List and WebId attributes are wrapped in { } as shown above, otherwise you will get these error messages with the Document Information Panel in Office apps:

Document Information Panel cannot create a new, blank form.

Document Information Panel cannot open the form. To fix this problem, contact your system administrator.

Form template: http://corp/sites/03/01/6900029913/proppanel.xsn

The following DataObject either cannot be created or cannot be initialized: list_1A6E8C1A-DB5C-428E-9DE1-941E6A836C05

Document Information Panel cannot add the following object to the DataObjects collection: list_1A6E8C1A-DB5C-428E-9DE1-941E6A836C05
list_1A6E8C1A-DB5C-428E-9DE1-941E6A836C05 could not be added to the DataObjects collection.

The following item already exists in the collection: list_1A6E8C1A-DB5C-428E-9DE1-941E6A836C05

or

The query cannot be run for the following DataObject: list_1A6E8C1A-DB5C-428E-9DE1-941E6A836C05

Document Information Panel cannot run the specified query.

The SOAP response indicates that an error occurred on the server:

Exception of type ‘Microsoft.SharePoint.SoapServer.SoapServerException’ was thrown.

0×82000006

List does not exist.

The page you selected contains a list that does not exist. It may have been deleted by another user.

Advertisement

About Bernado

Based in Australia, I am a freelance SharePoint and Dynamics CRM developer. I love developing innovative solutions that address business and everyday problems. Feel free to contact me if you think I can help you with your SharePoint or CRM implementation.
This entry was posted in Lookup Columns, SharePoint, SharePoint 2010. Bookmark the permalink.

4 Responses to How to create cross-web Lookup fields through XML schema

  1. Aryan says:

    but i want my custom lookup field should appear under heading “The type of information in this column is:”
    1.Single line of text
    2. Multi line of text
    .
    ..
    .
    .
    15. My Custom Lookup field should be there.

    • Bernado says:

      Hiya,

      What you are referring to would be a custom field type, not a field. Creating a custom field type would be a lot more involving than provisioning a field – which is what the original post was about. It would be a fun project though :).

  2. Manfred says:

    I wonder what went wrong:
    1.I created 3 lookup fields in one list pointing to another within the same site through the Sharepoint UI.
    2. I was surprised that I found all those fields added to ALL existing lists – throughout the whole sitecollection!
    3. I tried to delete them from all lists but:
    4. whenever I create a new list they are added no matter what list type, even a new calendar has them now – and ofc they show up in NewForm.aspx all over the place as well .

    What did I do wrong (I can’t reproduce it)?
    How can I avoid that they are ALWAYS injected into new lists?
    I guess there is a Schema, or several that defines standard list fields, any idea where that could be?

    • Bernado says:

      Hi Manfred,

      The only way that I can think of that this could have happened is that you added the fields to the Item content type at the site collection level. By default, new fields added to a content type at the site collection level will be pushed down to all children content types in the site collection. As Item is the parent content type for all content types in lists, newly created lists will inherit the fields you added to the Item content type.

      Go to the Item content type at the site collection and see if it contains the fields you added.

      Hope this helps.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s