question

ewinkiser avatar image
0 Votes"
ewinkiser asked MikeUrnun commented

Need to append a header row to a CSV File in a Logic App URGENT PLEASE

We found an issue in QA; I need to add a first row (Row #1) to an already existing CSV file which is a sink of a long pipeline. 81197-screenshot-2021-03-24-112823.jpg

The first row looks something like this:
05, ,2021-01-25, ,BMECOL, ,750

and I need to add it (as the first row) to the following:

82154-81197-screenshot-2021-03-24-112823.jpg

How can I insert this in Logic App as the first row to my already existing CSV file? It must be on the first row. I have googled until my fingers hurt :-). This is urgent to us. Thanks as always!

Mike Kiser


azure-logic-apps
· 3
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.

Hello @ewinkiser - Sounds like you're looking to prepend the new rows to the top of an existing .csv file, right?

1 Vote 1 ·

Hi @MikeUrnun

Yes, exactly; I have tried and tried and can not come up with a way successfully with ADF; I'm looking now into doing it with Logic Apps. Do you have any advice?

Thank you!
Mike Kiser

0 Votes 0 ·

Okay, that should be pretty straightforward -- thank you for confirming. I'll craft an answer with an example and post it here soon.

0 Votes 0 ·

1 Answer

MikeUrnun avatar image
0 Votes"
MikeUrnun answered MikeUrnun commented

Hello @ewinkiser

Since the content of a .csv file is a long string formatted as comma-separated-value where the new lines are delimited by \n character, you can use String Concatenation to ensure that, whenever your .csv file is updated with new rows, the new rows are always added to the top. In other words, it can be a workflow process of always placing a subset of new comma-separated text at the beginning of an existing such text whenever an update occurs to a .csv file.

Below is a very simple & basic example of such a workflow process with concatenation:
83115-image.png

For the example above, I chose an HTTP trigger for starting the workflow and Azure Blob for storing my sample cities.csv file. In the HTTP trigger, I specified that it should expect data for the new rows to be added in the Body of the request (done through JSON schema) and I named this new data as csvContent which represents my new rows. Next, I used the Azure Blob Storage connector to fetch the current and existing content of the CSV file before updating it with new content. I then do exactly that by using the Update Blob action to update the .csv file with the combined data of both csvContent + File Content data points.

If you're new to Logic Apps and/or have further questions, let me know and I'd happy to discuss. Depending on requirements, there are typically many other things to consider: average file size to be processed? how many files? character encoding, new lines character, etc.






image.png (106.6 KiB)
· 1
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.

@ewinkiser Just following up here, let me know if any questions.

0 Votes 0 ·