Expression Evaluation Time: ms / Round trip: ms
Create Cross-Web-Lookup Columns using PowerShell
15. Feb
2012
by Dario Category:
Technical
1

Unfortunatly it is not possible to create Cross-Web-Lookup columns directly in the SP UI or SP Designer (at least as far as I know).

However programatically or using Powershell it is possible.

Step 1) Open SP Administration Shell

Step 2) Get the webs and lists

$w1 = get-spweb "http://server/web1"
$w2 = get-spweb "http://server/web2"
$l1 = $w1.Lists["List"]
$l2 = $w2.Lists["Target List"]

Step 3) Add a lookup field

$l1.Fields.AddLookup("Lookup to Target List", $l2.ID, $false)

Step 4) Get the created lookup field

$lf = $l1.Fields["Lookup to Target List"]

Step 5) Here comes the magic - adjust the lookup web id and lookup field

$lf.LookupWebId = $l2.ParentWeb.ID
$lf.LookupField = $l2.Fields["Title"].InternalName
$lf.Update();
Comments
cyril
16.02.2012 08:49
Hi Dario, nice post, but the URL of the two webs should be different to really talk about a "cross-web" solution ;-).
(And to be fussy: the name of the field variable should be "$f1", just to have a consistent naming)
ABOUT

This blog is about technical and non-technical aspects of the product MatchPoint and other SharePoint topics.

If you would like to post an article or if you have an idea for a post, please contact us.

ARCHIVE
COMMENTS
Matthias Weibel
09.04.2018 01:12
Link is updated and works now. | Goto Post
Dhanabalan
09.04.2018 12:21
Link doesn't work. Could anyone explain what does... | Goto Post
matthiaszbrun
14.03.2018 02:05
Hi Markus
We I use the config for SiteCollectionSe... | Goto Post
Reto Jeger
04.10.2017 09:15
Hello Reiner,
Thanks for pointing out the missing ... | Goto Post
rganser
29.09.2017 09:56
Hi, I downloaded the ZIP-file for MatchPoint Versi... | Goto Post