none
Setting Multichoice column value in a Document Set in sharepoint online using powershell RRS feed

  • Question

  • Hi

    I am trying to update a document set multi choice column value, I am getting the choices in the choicevalues variable but document set when I update I dont get the values updated, whats wrong in $documentsetfolder.properties? below is my code

    function ImportCsvToSPOList($records,$spoCtx)
    {
        try
        {
            $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"]
            $cTypeID = $spoCtx.Site.RootWeb.ContentTypes.GetById("0x0120D520")
    
            $query = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery(10000, 'Title')
            $items = $list.GetItems( $query )
    
            $fieldCollection = $list.Fields
            
            $spoCtx.load($fieldCollection)
            $spoCtx.load($items)
            $spoCtx.Load($rootFolder)
            $spoCtx.ExecuteQuery();
    
            $field = $fieldCollection.GetByInternalNameOrTitle("City");
            $spoCtx.Load($field);
            $spoCtx.ExecuteQuery();
    
            $choicevalues = New-Object Microsoft.SharePoint.Client.FieldMultiChoice($spoCtx, $field.Path)
    
            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 column using their internal name
    
                if($documentsetfolder.Name -eq $row.'Name')
                {
                    
                    
                    #$choicevalues = New-Object Microsoft.SharePoint.Client.FieldMultiChoice($spoCtx, $field.Path)
                    
                    $choicevalues.Choices += $row.City
                    $count = $count + 1;
                    $choicevalues.Update();
                    $spoCtx.ExecuteQuery();
                  
                }      
            }
     catch  [Exception]
            {   
                Write-Host -ForegroundColor Red "An Error Occured"
                $_.Exception.Message
                $line = $logcount.ToString() + "," + $item["City"]+","+$_.Exception.Message;
                Add-Content $FailureLogs $line
            }
        }
                    $documentsetfolder.Properties['City'] = $choicevalues.Choices
                     
                    #Commit changes
                    
                    $documentsetfolder.Update();
                    $rootFolder.Update();
                    $list.Update();
                    $spoCtx.ExecuteQuery();
    
                    Write-Host -ForegroundColor Yellow "Number of record(s) inserted - "  $count
                    $line = $count.ToString() + "," + $documentsetfolder.Properties["City"];
                    Add-Content $SuccessLogs $line
        }
    


    Paru

    Sunday, April 22, 2018 9:35 PM

Answers

  • Hi,

    If you want to Setting Multichoice column value, you can refer to the following code.

    $choicevalues = New-Object Microsoft.SharePoint.SPFieldMultiChoiceValue;
    $choicevalues.Add("Green");            
    $choicevalues.Add("Blue");            
    $i["multiplechoicefield"] = $l.Fields["multiplechoicefield"].ParseAndSetValue($i,$choicevalues);            
    $i["multiplechoicefield"].ToString();            
    $i["multiplechoicefield"] = $choicevalues;            
    $i.Update();            
    #-or-            
    $l.Fields["multiplechoicefield"].ParseAndSetValue($i,$choicevalues);            
    $i.Update(); 

    You need to change the parameter according to your requirement.

    This is a reference about a similar case.

    https://sharepoint.stackexchange.com/questions/133320/how-to-set-a-multi-choice-field-value-in-a-sharepoint-list-using-powershell

    Best Regards,

    Carl Zhou


    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.

    • Marked as answer by Paru Upreti Thursday, May 3, 2018 8:26 AM
    Monday, April 30, 2018 6:13 AM

All replies

  • Hi,

     

    We are currently writing the code and will give you an update as soon as possible.

     

    Best Regards,

    CarlZhou


    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.

    Friday, April 27, 2018 6:32 AM
  • Hi,

    If you want to Setting Multichoice column value, you can refer to the following code.

    $choicevalues = New-Object Microsoft.SharePoint.SPFieldMultiChoiceValue;
    $choicevalues.Add("Green");            
    $choicevalues.Add("Blue");            
    $i["multiplechoicefield"] = $l.Fields["multiplechoicefield"].ParseAndSetValue($i,$choicevalues);            
    $i["multiplechoicefield"].ToString();            
    $i["multiplechoicefield"] = $choicevalues;            
    $i.Update();            
    #-or-            
    $l.Fields["multiplechoicefield"].ParseAndSetValue($i,$choicevalues);            
    $i.Update(); 

    You need to change the parameter according to your requirement.

    This is a reference about a similar case.

    https://sharepoint.stackexchange.com/questions/133320/how-to-set-a-multi-choice-field-value-in-a-sharepoint-list-using-powershell

    Best Regards,

    Carl Zhou


    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.

    • Marked as answer by Paru Upreti Thursday, May 3, 2018 8:26 AM
    Monday, April 30, 2018 6:13 AM
  • thanks!!

    Paru

    Thursday, May 3, 2018 8:26 AM