Lookup Field as a Site Column via CAML

Posted by Rob Windsor on Stack Overflow See other posts from Stack Overflow or by Rob Windsor
Published on 2009-07-16T17:17:26Z Indexed on 2010/06/08 0:32 UTC
Read the original article Hit count: 250

Filed under:

I'm trying to create a Lookup Field as a Site Column via CAML. The list I want to use as the source of the lookup is created in the Feature Receiver so I don't know it's ID. I've read several blog posts that indicate that I can just put the path to the list in the List attribute. It seems from the comments on these post that this solution works for some people but not for others. I'm in the latter group.

When I try to associate a content type that uses the lookup site column I: "Exception from HRESULT: 0x80040E07"

<Field 
  ID="{da94e56b-428f-4b95-b4c6-24aed0256475}" 
  Name="Test_x0020_Lookup_x0020_Column"
  StaticName="Test_x0020_Lookup_x0020_Column" 
  DisplayName="Test Lookup Column" 
  Type="Lookup" 
  Required="FALSE" 
  List="Lists/Test" 
  ShowField="Title" 
  PrependId="TRUE"
  Group="Test Site Columns" />

  <ContentType
    ID="0x0100B6D92594DDCE8E479D0EB0C414C463B0"
    Name="Test Lookup Content Type"
    Version="0"
    Group="Test Content Types">
    <FieldRefs>
      <FieldRef 
         ID="{da94e56b-428f-4b95-b4c6-24aed0256475}" 
         Name="Test_x0020_Lookup_x0020_Column" 
         Required="TRUE" />
    </FieldRefs>
  </ContentType>

© Stack Overflow or respective owner

Related posts about sharepoint