none
Setting multivalue lookup column value in a document set in sharepoint online RRS feed

  • Question

  • Hi

    I am trying to update the document set multi value choice lookup column, below code gives no error but does not update the values :(

    please help

    function ImportCsvToSPOList($records,$spoCtx)
    {
    
            $count = 0;
            $logcount = 0;
            [Microsoft.SharePoint.Client.Web]$web = $spoCtx.Web
            [Microsoft.SharePoint.Client.List]$list = $web.Lists.GetByTitle($records.LibraryName)
            
            $rootFolder = $list.RootFolder.Folders
    
            $cType = $list.ContentTypes["ABC"]
            #$fields = $list.Fields;
    
            $query = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery(10000, 'Title')
            $items = $list.GetItems( $query )
     
            $spoCtx.load($items)
            $spoCtx.Load($rootFolder)
            $spoCtx.ExecuteQuery();
    
            Write-Host "Starting Data Import" -ForegroundColor Yellow
    
            foreach($documentsetfolder in $rootFolder)
            {
            #read all the values from csv
            foreach($row in $CSVLocation)
            {
                $logcount = $logcount + 1;
            try
            {
                [Microsoft.SharePoint.Client.ListItemCreationInformation]$itemCreateInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation;
                [Microsoft.SharePoint.Client.ListItem]$item = $list.AddItem($itemCreateInfo); 
         
                #importing values of each coumn using their internal name
                 if($documentsetfolder.Name -eq $row.'city')
    
                {
    $count = $count + 1;
    $mvLookup = $documentsetfolder.Properties["city"]
    
    $mvLookup |% { "Lookup Value: $($_.LookupId):$($_.LookupValue)" } 
    
    # create an Object[] and add FieldLookupValue instances 
    
    $lookupValueCollection = @() 
    
    $lookupValue = New-Object Microsoft.SharePoint.Client.FieldLookupValue 
    
    $lookupValue.LookupId = 1
    $lookupValueCollection += $lookupValue 
    $lookupValue = New-Object Microsoft.SharePoint.Client.FieldLookupValue 
    
    $lookupValue.LookupId = 2
    $lookupValueCollection += $lookupValue 
    # convert the Object[] to a FieldLookupValue[] 
    $mvLookup = [Microsoft.SharePoint.Client.FieldLookupValue[]]$lookupValueCollection  
    
    $documentsetfolder.Properties["city"] = $mvLookup.ToString()
    
    $rootFolder.Update();
    $list.Update();
    $spoCtx.ExecuteQuery();
    
    Write-Host -ForegroundColor Yellow "Number of record(s) inserted - "  $count
    
    $line = $count.ToString() + "," + $documentsetfolder.Properties["Contract_x0020_Partners"];
    Add-Content $SuccessLogs $line
    
                } 
            }
    
    
    
    
    
    Paru

    • Edited by Paru Upreti Sunday, April 22, 2018 2:21 PM code update
    Friday, April 20, 2018 3:14 PM

All replies

  • Hi Paru,

    To set multiple lookup field value for a document set, the following example code for your reference:

    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
    
    $SiteURL="https://xxx.sharepoint.com/sites/dennis"
    $UserName="dennis@xxx.onmicrosoft.com"
    $Password = "xxx"
     
    $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
    $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,$SecurePassword)
    
    #Bind to Site Collection
    $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $ctx.Credentials = $Creds
    
    $web = $ctx.Web
    $list = $web.Lists.GetByTitle("DL")
    
    $rootFolder = $list.RootFolder.Folders
    $ctx.Load($rootFolder)
    $ctx.ExecuteQuery()
    
    foreach($documentsetfolder in $rootFolder)
    {
    	if($documentsetfolder.ProgID -eq "Sharepoint.DocumentSet")
    	{
    		$listItem = $documentsetfolder.ListItemAllFields;
    		$lookupValueCollection = @()
    		$lookupValue = New-Object Microsoft.SharePoint.Client.FieldLookupValue 
    
    		$lookupValue.LookupId = 1
    		$lookupValueCollection += $lookupValue 
    		$lookupValue = New-Object Microsoft.SharePoint.Client.FieldLookupValue 
    
    		$lookupValue.LookupId = 2
    		$lookupValueCollection += $lookupValue 
    		#convert the Object[] to a FieldLookupValue[] 
    		$mvLookup = [Microsoft.SharePoint.Client.FieldLookupValue[]]$lookupValueCollection  
    
    		$listItem["city"] = $mvLookup		
    		$listItem.Update()
    		$ctx.ExecuteQuery()
    	}
    }

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Monday, April 23, 2018 8:18 AM
    Moderator
  • Hi,

    Would you please provide us with an update on the status of your issue?

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Thursday, May 3, 2018 8:16 AM
    Moderator
  • Thanks for the reply Dennis, i was stuck in another issue, working on this now, i will update today if it works, as it is a priority task now.

    Paru

    Thursday, May 3, 2018 8:27 AM