I have worked on a PowerShell PnP script to update a column in a cloud-based SharePoint list. I want to update the column “Parent ID” with the content from “FH ID”. My script works fine on a regular column, but “Parent ID” is a lookup-column and therefore, it has three values: LookupID, LookupValue and TypeId (see image). My script updates LookupId, but we need it to update LookupValue.
Can anyone help with a solution?
In the below script we are testing on one “FH ID” = 1020
enter code here
Connect-PnPOnline https://skat.sharepoint.com/sites/ICIfo
function UpdateColumn(){
$listName = "FH kontakt"
$list = Get-PnPList $listName
$items = Get-PnPListItem $listName
foreach ($item in $items){
if ($item["FH_x0020_ID"] -eq "1020"){
Write-Output $item["FH_x0020_ID"]
Write-Output $item["FH_x0020_Navn"]
Write-Output $item["Parent_x0020_ID"]
Write-Output ""
Set-PnPListItem -List $listName -Identity $item -Values @{"Parent_x0020_ID" = $item["FH_x0020_ID"]}
}
}
}
UpdateColumn
To update the lookup column in SharePoint online, you need to get the ID of the parent lookup item.
You could refer to this article for more:
https://www.sharepointdiary.com/2017/03/sharepoint-online-powershell-to-update-lookup-field.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.