question

JonLawton-2392 avatar image
0 Votes"
JonLawton-2392 asked EchoDu-MSFT commented

Add-PNPListItem - Multiple choice values in CSV import

I have a regular PowerShell script that I use and modify to insert items into SharePoint lists from CSV files. It uses Add-PNPListItem in a foreach loop from the imported CSV and has worked great over time.

I have come across the need to import data into a SharePoint list where the column in list is a Choice field allowing multiple values.

In my CSV, these values are separated by a comma (,) and the values match the options in the Choice field.

When the data is imported I can see them in the view as Blood, Pathology (2 options chosen) but when I edit the item, the column just says please select and the options are not ticked. You need to then re-tick the options before saving because if you don't, it will wipe out the values imported.

My question is how should I approach this? Clearly having the values separated with a comma isn't working. I did make the CSV pipe delimited (|) so it would not see the comma in the CSV as a column separator.

I'm not sure how to get the values recognised by the choice column so they are ticked.

I have attached some screen shots showing what the value looks like in the view and then what happens you edit an item with multiple values.

This does not happen when there is only 1 value in the source.

Thanks - Jon

97469-multi.jpg


office-sharepoint-online
multi.jpg (56.6 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

EchoDu-MSFT avatar image
0 Votes"
EchoDu-MSFT answered EchoDu-MSFT commented

Hello @JonLawton-2392 ,

Welcome to Q&A Forum!

Please following steps:

1.In the CSV file, these values are separated by a comma (;#) and the values match the options in the Choice field (Allow multiple selections).

97822-1.png

97790-2.png


2.Use the below PowerShell import CSV to SharePoint List.

 #Parameters
 $SiteUrl = "https://tenant.sharepoint.com/sites/Echo"
 $ListName = "TestingCSV"
 $CSVPath = "C:\Temp\TestingCSV.csv"
     
 #Get he CSV file contents
 $CSVData = Import-CsV -Path $CSVPath
     
 #Connect to site
 Connect-PnPOnline $SiteUrl -UseWebLogin
     
 #Iterate through each Row in the CSV and import data to SharePoint Online List
 foreach ($Record in $CSVData){
    
     Add-PnPListItem -List $ListName -Values @{
         "Title"= $Record.'Title';
         "Test"= $Record.'Test';
         "TestDetails"= $Record.'TestDetails'
     };
 }

97816-3.png

97817-csv.gif


Thanks,
Echo Du
===========================
If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.





1.png (49.8 KiB)
2.png (38.4 KiB)
3.png (43.5 KiB)
csv.gif (731.2 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @JonLawton-2392 ,

Is there anything else I can help with regarding this issue?
You can comment us at any time and we will continue to follow up.

Thanks,
Echo Du

0 Votes 0 ·

Hi @JonLawton-2392 ,

Would you tell me whether your issue has been resolved or have any update?
I am looking forward to your reply.

Have a nice day!

Thanks,
Echo Du

0 Votes 0 ·