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

Mike Kiser 1,531 Reputation points
2021-03-28T17:49:18.69+00:00

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
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
2,873 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Mike Urnun 9,761 Reputation points Microsoft Employee
    2021-03-31T05:52:29.38+00:00

    Hello @Mike Kiser

    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.