,

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

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930