,

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

December 2024
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
3031