Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have SharePoint site collection 'http://microsoft.com/' with few child webs ex: http://microsoft.com/news/

I want to create lookup field to 'Pages' list. On each child web lookup field should point to current web 'Pages' list.

Currently all my created fields are related with 'Pages' lib on root site.

I got field definition:

<Field Name="LookupToPages" 
   ID="{3B5B07A0-68DB-4BF6-AAAE-87B77CE430C6}"
         Type="LookupMulti"
         DisplayName="Related News"
         Group="Intranet.ContentTypes"
         Mult="TRUE"
         Overwrite="TRUE"
         SourceID="http://schemas.microsoft.com/sharepoint/v3"
         List="Pages"
         ShowField="Title"/>

This field added to my content type that used in Pages lib:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <ContentType ID="0000"
                Name="News"
               Group="my froup"
               Description="Page layout for intranet news."
               Inherits="TRUE"
               Version="0">    
    <FieldRefs>
      <FieldRef ID="{3B5B07A0-68DB-4BF6-AAAE-87B77CE430C6}" Name="LookupToPages" />
    </FieldRefs>
  </ContentType>
</Elements>

I tried to add field definition to feature with scope 'Site' and 'Web'. Both of them has same results. I just have Lookup column that points to root site.

How to make this field web related?

share|improve this question
    
do you mean to add the lookup field with the page library? –  Falak Mahmood Jan 6 '13 at 17:02
add comment

3 Answers

up vote 3 down vote accepted

Evgeny,

If this is a lookup to the list it self (i.e. you want to select elements form the same list, like related news articles) you can set the list property to "self".

<Field Name="LookupToPages" ID="{3B5B07A0-68DB-4BF6-AAAE-87B77CE430C6}" Type="LookupMulti" DisplayName="Related News" Group="Intranet.ContentTypes" Mult="TRUE" Overwrite="TRUE" SourceID="http://schemas.microsoft.com/sharepoint/v3" List="Self" ShowField="Title"/>

see here for further information:

http://msdn.microsoft.com/en-us/library/aa979575.aspx

share|improve this answer
add comment

Evgeny,

I recommend you utilize an event receiver if you're provisioning the list or content type through a feature.

In short, what you need to do is to create the lookup column on the list, get a field link to the new column, and then add the field link to the content type attached to the list.

Something like this should do the trick, provided you have myList, myListCT and pageList objects already:

string fieldName = myList.Fields.AddLookup("Page Column Display Name", pageList.ID, true);
SPField field = myList.Fields.GetFieldByInternalName(fieldName);
SPFieldLink fieldLink = new SPFieldLink(invoiceField);
myListCT.FieldLinks.Add(invoiceFieldLink);
myListCT.Update();

.b

share|improve this answer
add comment

In SP2013, you can create a Lookup column. In the "Get Information From" field, choose Site Pages.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.