Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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

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

I recommend you to use JSOM because it can be used in O 365 easily too. You can Use the method: fieldCollection.addFieldAsXml(fieldSchema, true, SP.AddFieldOptions.addToDefaultContentType);

See for further information: http://josharepoint.com/2015/12/02/create-a-new-lookup-field-using-jsom-in-sharepoint-2013-office-365/

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top