Hello everyone!
I am creating a Lookup field in a custom list by powershell. I did it with the following code:
$spWeb = Get-SPWeb -Identity $url
$list = $spWeb.Lists["TargetList"]
$ParentList = $spWeb.Lists["ParentList"]
$list.Fields.AddLookup("LookupName",$ParentList.id,$true)
This code creates the lookup field. Now I want to conifgure this lookup field to related with the field "Title" of the parent List, because in default it is pointed to the field "ID":
$SPChildListLookupField = $list.Fields["LookupName"]$SPChildListLookupField.LookupField = $ParentList.Fields["Title"].internalname
$SPChildListLookupField.Update()
$spWeb.Dispose()
The problem comes that when I check the lookup field it is still related to the field "ID" from the parent list... The code is in a .ps1 file. However, if I copy and paste directly the code to the SHP powershell console it works correctly and the lookup field is pointing to the field "Title" of the parent list.
Any idea on what could be the problem? Becuase I tryed and searched everything.
Thanks,
Luis.


