I have a multi values lookup column. I'm trying to update another column on another list from a lookup column. So let say I have values in a lookup column like so:
1;#Open 2;#Close 3;#Closed
I want to use this values to update another column that uses a lookup column. I can update if its one value e.g. 1;#Open
But when I have multiple values (e.g. the 3 of them) I get error :
Cannot convert value "Event Type" to type "System.Int32". Error: "Input string was not in a correct format."
$CMRSItems = $list.Items | where {$_['ID'] -le 5}
$CMRSItems | ForEach-Object {
$val = GetFormattedValue -val $_['Event TypeOld']
Write-Host "RefID: " $_['RefID']
$t = $val -replace ";"," "
$array = @($t)
foreach ($i in $array) {
$c = $array.Count
write-host $c
$r = GetLookUpValues -val $i
#Write-Host $r
$documents = New-Object Microsoft.SharePoint.SPFieldLookupValueCollection($r);
for ($i = 0; $i -lt $array.Count; $i++)
{
$CMRSItems["Event Type"] = $documents[$i];
$CMRSItems.Update()
}
}
}
function GetFormattedValue([string]$val)
{
$tvalue = $val.Split("#") -match "\d{1,3}"
return $tvalue
#-replace ";","`t"
}
function GetLookUpValues([string] $val)
{
foreach ($item in $lookupitem.GetItemById($val))
{
$lookupvalue = New-Object Microsoft.SharePoint.SPFieldLookupValue($item.ID,$item.Name.ToString());
#Write-Host "lookupcol value" $lookupvalue
}
return $lookupvalue
}