,

Create Lookup on List in another Web

Here is a simple powershell script, that creates Lookup column on targetList from sourceList.


$targetWeb = Get-SPWeb http://web.domain.local/site/webroot/web1/
$targetList = $targetWeb.Lists.TryGetList("Target List Name")

$sourceWeb = Get-SPWeb http://web.domain.local/site/webroot/anotherweb/
$sourceList = $sourceWeb.Lists.TryGetList("Source List Name")

$targetList.Fields.AddLookup("NewLookup", $sourceList.id, $false)
$LookupField = $targetList.Fields["NewLookup"]
$LookupField.Required = $false
$LookupField.LookupWebId = $sourceList.ParentWeb.ID
$LookupField.LookupField = $sourceList.Fields.GetField("FieldNameToDisplay").InternalName
$LookupField.Update();


Leave a Reply

Your email address will not be published. Required fields are marked *

About me

I am web developer, tech enthusiast and fitness junkie 🙂

Calendar

July 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
293031