1

I am trying to setup a cross-site lookup field using XML (which I have been able to do in past SharePoint On-Premises environments). I am having some difficulties however creating a similar configuration in my SharePoint Online tenant based environment.

My target configuration has the following details:

  1. Two Team (modern) sites, both at same site level, and both associated with a Team (hub) site.
  2. SiteA has a list of projects/products.
  3. SiteB has a list of records containing a lookup field which needs to point to the Project list on SiteA.

Right now, I am just trying to create a Site Column on SiteB that will be a lookup field pointing to the Project List on SiteA. Since I know that this configuration cannot be done in the OOB user interface, I am using PowerShell 5.1 commands and PnP library cmdlets to do this via XML. When I execute the lines below, a Site Column is created at SiteB, but it does not actually appear to be connected to the Project List (SiteA) so there are no values when I use it to create a column in a list. I have also tried directly creating a column in a list (to see if that would work better).

To the XML below, I am specifying the GUID of the list on SiteB which contains the list of projects and the GUID of the Web context for SiteB. I am using NewGuild to generate a new GUID for the new site column.

Some samples of my PS code:

$newguid = [GUID]::NewGuid()

$fieldXML = '<Field ID="' + $newguid + '" 
Type="Lookup" Name="TestProj4" 
DisplayName="TestProj4" Static
Name="TestProj4" Group="TestColumns" 
List="{7840346f-d83a-4111-806b-6f97db6f0bc6}" 
WebId="e3ab472f-0146-4229-abdd-36f9b4aabeb8" 
ShowField="Title" Required="TRUE" EnforceUniqueValues="FALSE" />'

Add-PnPFieldFromXml -FieldXml $fieldXML

One thing that I have noticed (and which has puzzled me) is that when I use Get-PnPWeb to get (what I believe to be) the WebID, the GUID returned is exactly the same for both SiteA and SiteB. I have used separate PowerShell consoles to extract information for the sites separately to make sure that the commands are operating on the correct sites. So I am wondering if I am using the correct GUID in my XML (for WebId) to point to the Web (or site) containing the project list.

I am going to keep trying things, but I am hoping that someone might have some suggestions or insights for how to configure the XML for SharePoint Online and set the cross-site lookup successfully.

UPDATE to Original Question

I have been continuing to work on this issue. I had been working with two Team sites which are both associated with a Hub site. But then I decided to try working with two different Team sites - not associated with any Hub sites. In this case, the WebID (LookupWebIDs) were different from each other. So, I reconfigured my XML and used Add-PnPFieldFromXML which created a new Site Column (no errors), and property values for new column checked out as desired.

$fieldXML = ‘<Field Type="Lookup" DisplayName="TestColumnA" Required="FALSE" EnforceUniqueValues="FALSE" List="{9e887b1f-12ad-4feb-a1f8-a9fe5d15b6ab}" WebId="8ff42b00-5858-4f6d-8295-80aff7950373" ShowField="Title" UnlimitedLengthInDocumentLibrary="FALSE" Group="TestColumns" ID="{e06edaad-7b83-4be9-9fec-52e2eb9b92f0}" SourceID="{8ff42b00-5858-4f6d-8295-80aff7950373}" StaticName="TestColumnA" Name="TestColumnA" Description="Test column for cross-site lookup"  />’

Add-PnPFieldFromXML -fieldXML $FieldXML (to create the new Test Column on Site A)

*Check properties*
PS C:> $testCol.LookupList
{9e887b1f-12ad-4feb-a1f8-a9fe5d15b6ab}
PS C:> $testCol.LookupWebID

Guid
----
8ff42b00-5858-4f6d-8295-80aff7950373

But when I tried to use the new column in a list - the pulldown has no values (should be 3 values) - so still does not seem to be correctly connecting to list on other site.

UPDATE 2 - One possible solution -----------------------------------

I was finally able to get the cross-site capability using PowerShell/GUID/XML to set the SchemaXML property of a lookup field in my list (SiteB) to point to list of values (SiteA). GUIDs for List, WebID, and SourceID were set to cross-site values and everything worked as expected. However, I first had to create a Classic Site Collection (on my Online tenant) so that I could then create two Team sites using the Classic SharePoint Team Site template.

No matter what I tried, I could not get the cross-site capability working with a Modern Team Site template. For me, it only seems to work in sites created with the Classic template. It is still important to find a solution that will allow cross-site lookup capability using the Modern configuration, so this issue is still unresolved. I just wanted to share what did work - in case it helps someone else.

1

Technically, team sites are separate site collections. You're not able to create a lookup field pointing to a list from another site collection. As I understood, finally, you created two subsites within the same site collection via classic UI and after that the lookup field started working properly.

  • Thank you for your response and comments. Yes, I created a Site Collection using the Classic UI, then created two sub-sites using the Classic configuration. Then the cross-site lookup field worked correctly. The cross-site capability does not seem to work with the Modern Team sites because as you indicated, they are all site collections now. But if we build our sites using Classic, we don't know how much longer this option will be supported in SharePoint Online. – KSRayGS Aug 28 at 14:25
0

Once I fully understood that Modern Team Sites function as individual site collections, I created 2 sites under the level of one of my new Team Sites. I chose the template option for no 365 group. This create sub-sites with the new modern layout and functionality - but which also supported unique Web IDs. I was able to update the field schema in the site requiring a cross-site lookup (to the other site) - and it worked perfectly. I realize that I have created a slight hierarchy with this - which I understand is something that SharePoint is trying to discourage. However the cross-site lookup capability is a very critical requirement for us. This solution supports the needed cross-site lookup capability and still allows the use of the modern pages with native capabilities. This will work for us.

Many thanks to @Dmitry whose words prompted me to finally realize that Modern Team sites are not quite the same as the old team site template that I have been used to since SharePoint 2003.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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