cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
shelleyb
Regular Visitor

Formatting csv file from SharePoint list 'multi choice columns'

 

Hello,

 

I have an 'flow' to create a CSV file and send to distribution list based on the values within a SharePoint list. It works to a point. The issue is the format of the CSV file; the majority of the columns are formatted like (see below); there is 11+ multi choice columns on the SharePoint list.

 

{"@odata.type":"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference","Id":2,"Value":"New"} 

 

FlowOverview.JPG

 

I've attempted to format using the following articles with no luck; I'm obviously missing something:-

EDIT: 

@Paulie78 @Hardesh15 I've tried the 'Select' option to format as suggested its there that the below error message appears stating logic is invalid and flow is exceeding the limited of 'Apply to Each'. I'm selecting the 'Value' options for the columns required and Power Automote automatically applies the 'Apply to Each' container.

 

PowerAutomateEFT-SelectError.JPG

1 ACCEPTED SOLUTION

Accepted Solutions
Paulie78
Super User III
Super User III

Hi Shelly,

 

This is a little complicated due to the way you have the arrays within your array, but I have tried to make it as simple as possible. This is how it works...

 

  1. Each SharePoint Row is loaded into an apply/each loop.
  2. Within that apply/each loop each array within the record is transformed to a flat array of values.
  3. Still within the apply/each loop a JSON is created within a compose action.
  4. Within the compose action the new arrays are joined with a semi-colon in order to work with the CSV.

Outside of the apply to each all of the unique rows are combined into an array and then fed into the input of the create csv action. 

 

Here is an image of the flow: https://ibb.co/vhpGrsR

SharePointToCSV.jpg

Now there is probably quite a bit here you are not familiar with. To make it easier for you I have exported my flow and uploaded so you can download it and import it into your environment, to copy each step:

https://www.tachytelic.net/wp-content/uploads/SharePointToCSV2_20210202174524.zip

Note that my first action "Get items" is actually a OneDrive get file content action. But I named it "Get items" so that the code produced would be the same as what you need. You need to delete the "Get items" step and replace it with your SharePoint Get Items action.

I have not done every field for you, I have done enough fields so that you can copy the example and produce exactly what you need.

 

View solution in original post

16 REPLIES 16
Hardesh15
Super User II
Super User II

@shelleyb You are not selecting correct column name from dynamic content. Pls elaborate more.

 

Please 'Thumbs Up' the posts that helped you and 'Mark as Solution' if my post answered your question.

@Hardesh

Paulie78
Super User III
Super User III

Probably the easiest thing to do is use a "select" action after the get items action to reformat the output from sharepoint to be just how you want it. You can then use the output of the select action in your create CSV action.

Paulie78
Super User III
Super User III

Could you do me a favour and then I will help you out. Could you post the complete output (JSON) for your get items action on pastebin.com. Then I will bring that into a flow on my end and put you something together that will do what you want.

shouldn't be a problem... how do I get the (JSON) output? 

Paulie78
Super User III
Super User III

In the run history, click on the "Get Items" step, and copy the contents of the "outputs" section. It might say click to download if it is over a certain size.

Paulie78
Super User III
Super User III

ok, I had a look, it isn't as straightforward as I imagined. The choice fields are no problem and the values can be retrieved with a select query. The problem comes when you get to the field named "Front_x0020_End". This is because this is an array within an array (it can have many choices).

So how would that be represented in CSV? (It would have to be a single column separated by something other than a comma).

 

Example CSV output of the fields up to that point is like this:

Title,ID,storeNumber,storeName,project,newExistingStore,newExistingStoreID,goLiveDate,eftRequiredDate,submittedWithinSLA,outsideSLA
Sainsburys,889,0,Test6,New Store,New,2,2021-02-01,2021-02-01,Yes,Project Late Request

Do you know what I mean?

 

yeah that would be perfect: single column with the multi choice separated by ;

Paulie78
Super User III
Super User III

Hi Shelly,

 

This is a little complicated due to the way you have the arrays within your array, but I have tried to make it as simple as possible. This is how it works...

 

  1. Each SharePoint Row is loaded into an apply/each loop.
  2. Within that apply/each loop each array within the record is transformed to a flat array of values.
  3. Still within the apply/each loop a JSON is created within a compose action.
  4. Within the compose action the new arrays are joined with a semi-colon in order to work with the CSV.

Outside of the apply to each all of the unique rows are combined into an array and then fed into the input of the create csv action. 

 

Here is an image of the flow: https://ibb.co/vhpGrsR

SharePointToCSV.jpg

Now there is probably quite a bit here you are not familiar with. To make it easier for you I have exported my flow and uploaded so you can download it and import it into your environment, to copy each step:

https://www.tachytelic.net/wp-content/uploads/SharePointToCSV2_20210202174524.zip

Note that my first action "Get items" is actually a OneDrive get file content action. But I named it "Get items" so that the code produced would be the same as what you need. You need to delete the "Get items" step and replace it with your SharePoint Get Items action.

I have not done every field for you, I have done enough fields so that you can copy the example and produce exactly what you need.

 

View solution in original post

tom_riha
Super User II
Super User II

Hello @shelleyb ,

I think these two posts in the topic you linked show the solution:

I'd just extend the expression by adding join(...) to display the choices not as an array ["choice1","choice2"] but as a semicolon separated string.

join(xpath(xml(json(concat('{"body":{"value":', item()?['COLUMN_NAME'] , '}}'))), '/body/value/Value/text()'), '; ')

 

image.png



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

@Paulie78 Thank you! I'm now getting the following error message

 

CurrenFlowProcess.pngErrorMessage.png

Paulie78
Super User III
Super User III

Hi @shelleyb ,

This means that the output of the compose step "completeJSON" is empty. If you go into the run history you can verify if this is the case. If it is empty, please check if the apply to each section ran. If it did, check there was some output in rowJSON compose step. If that didn't run, ensure that "Get items" actually returned some data.

Cool … it looks like the connection between rowJSON and completeJSON isn't working.

 

And the outputs from rowJSON aren't showing for completeJSON

 

JSON.JPG

Paulie78
Super User III
Super User III

Try putting in the expression:

 

outputs('rowJSON')

in the completeJSON step. It seems to be empty right now.

 

its still coming up with the error. The output from rowJSON is empty

Paulie78
Super User III
Super User III

My guess is that your apply to each never ran. Look into the run history and see how many iterations of the apply/each loop ran please.

Helpful resources

Announcements
Process Advisor

Introducing Process Advisor

Check out the new Process Advisor community forum board!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,376)