Appending CSV File Using String Builder

Last Updated: 06/07/2018 Introduced in Version: 2.0

This tutorial demonstrates how to append new rows to the CSV file using String Builder steps. These steps can be found in Data > Text > Builder category in the ToolBox.

 

Example:

We begin in the Designer Folder with clicking Create Flow on the Folder Actions panel.

Then, we Name the Flow and click Create to proceed to the Flow Designer.

 

 

First, we need to create Data that will hold our CSV file. We add Create Data step from Favorite Steps category in the Quick Add Step dialog.

 

 

In the resulting pop-up we click Add New link to add new Data Definition.

 

 

In the Add DataDefinitions window we Name our Data and define its Type FileData. Then we click Ok to save and close this pop-up window.

 

 

When we finished defining our Data we click Add in the Data Definitions window to continue.

 

 

To use Text Builder steps in the Flow we need to Create a String Builder first. We add Create String Builder step from All Steps [Catalog] > Data > Text > Builder category in the Step panel.

 

 

Because the Contents of our CSV file is of type Byte Array, we add Get String From Bytes step from All Steps [Catalog] > Data > Text category to convert CSV file Contents into String.

 

 

Next, we can pick a CSV file for our Create Data step. The CSV file we are going to work with in this Example looks as following…

 

 

We select Create Data step on the workspace and Step Information Layer pops up. Then, we use Choose File for our OriginalCSVFile Data in the Inputs section to select the desirable file.

 

 

Next, we need to Append the String from Original CSV File to our String Builder. We add Append Line step from All Steps [Catalog] > Data > Text > Builder category.

 

 

Then, to map data for the Get String From Bytes step we select Edit Input Mapping from step’s Options Menu.

 

 

In the Mapping Editor we expand OriginalCSVFile and connect its Contents to the bytes field. Click Ok to save and close Mapping Editor.

 

 

Back in the Flow Designer we call Edit Input Mapping for Append Line step.

 

 

In the Mapping Editor we connect CreateStringBuilder_Output to the data field and GetStringFromBytes_Output to the lineToAdd field. Then save and close Mapping Editor.

 

 

Next, we are going to create a simple Form for the user to be able to add new rows. We add Show Form step from Favorite Steps category in the Step panel.

 

 

In the resulting pop-up window we Name the Form and click Create to proceed to the Form Designer.

 

 

This simple Form is designed as following… It has a Title implemented with Label component from the Data category. Then, it has a Text Box Multi Line component from Data category for user to input new Rows. And, it has Done button, implemented with Button component from Actions category. When we finish designing our Form we can save and close Form Designer.

 

 

Next, we are going to add new rows from the Form step to the String Builder. We add Append Text step from the All Steps [Catalog] > Data > Text > Builder category in the Steps panel.

 

 

Then, we Edit Input Mapping for this step.

 

 

In the Mapping Editor we connect CreateStringBuilder_Output to the data field. Then, we connect NewRows outcome from the Form step to the textToAdd field. Click Ok to save and close Mapping Editor.

 

 

Back in the Flow Designer we add To Text step from the All Steps [Catalog] > Data > Text > Builder category in the Steps panel. With this step we are able to retrieve Data from the String Builder in the form of String.

 

 

We select Show Mapping Editor option to map Data for the To Text step.

 

 

In the Mapping Editor we connect CreateStringBuilder_Output to the string builder field. Then, we click Ok to save and close Mapping Editor.

 

 

Next, we add Get Bytes From String step from All Steps [Catalog] > Data > Text category in the Steps panel. With this step we are going to convert String output from To Text step into an Array of Bytes. Then we will be able to use this Array of Bytes as Contents for our New CSV file.

 

 

We use Step Information Layer to map data to this step. For the str field in the Inputs section we choose Select Value Mapping type, and using Path picker point to the ToText_Output.

 

 

We add Show Form step from Favorite Steps category in the Steps panel. This Form will serve for the user to be able to Download an updated CSV file.

 

 

In the resulting pop-up window we Name the Form and click Create to proceed to the Form Designer.

 

 

This Download File Form is designed as following… It has a Title that is displayed with a Label component from the Data category. It has a Close Button control from the Actions category. Finally, it has File Download component from File Handling category. With this control user will be able to download the File that is mapped to this control. We save the Form and close Form Designer, when finished.

 

 

Back in the Flow Designer we connect Close outcome from Download File Form to the End Step in our Flow. Then, we select Edit Input Mapping from the Download File Form’s Options.

 

2016-12-16_145419

 

In the Mapping Editor we use Build Data Mapping type for the DownloadFile control.

 

2016-12-16_145509

 

Next, we connect GetBytesFromString_Output to the Contents field. Note, that we need to use .csv file extension in the FileName field. We can save and close Mapping Editor.

 

2016-12-16_145723

 

This completes our Flow. We click Debug Flow link on the top panel in the Flow Designer to test our Flow.

 

 

Our Form for adding new rows opens in the Debugger. We add new coma separated rows and click Done.

 

 

Then, our Download File Form opens in the Debugger. We click Download File…

 

 

Next, we Name our file and save it.

 

 

We click Close on the Download File Form…

Diagram Tab in the Debugger indicates that our Flow ran to the End Step with no errors.

 

 

We locate and open our New CSV file… Confirm that new rows of Data were added.

 

2016-12-16_150709

 

 

Additional Resources