Appending CSV File Using String Builder
  • Updated on 08 Jan 2015
  • 5 minutes to read
  • Print
  • Dark
    Light

Appending CSV File Using String Builder

  • Print
  • Dark
    Light

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.
2018-03-30_1029172.png

Then, we Name the Flow and click Create to proceed to the Flow Designer.
2018-01-15_092158.png

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**.**
2018-01-15_092325.png

In the resulting pop-up we click Add New link to add new Data Definition.
2018-01-15_0927231.png

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.
2018-01-15_092723.png

When we finished defining our Data we click Add in the Data Definitions window to continue.
2018-01-15_093257.png

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.
2018-01-15_093610.png

2018-01-15_093710.png

Because the Contents of our CSV file is of type Byte Array , we add Get String From Bytes step fromAll Steps [Catalog] > Data > Text category to convert CSV file Contents into String .
2018-01-15_094513.png

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…
2018-01-15_094657.png

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.
2018-01-15_094832.png

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.
2018-01-15_095215.png

Then, to map data for the Get String From Bytes step we select Edit Input Mapping from step’s Options Menu.
2018-01-15_095630.png

In the Mapping Editor we expand OriginalCSVFile and connect its Contents to the bytes field. Click Ok to save and close Mapping Editor.
2018-01-15_095805.png

Back in the Flow Designer we call Edit Input Mapping for Append Line step.
2018-01-15_095913.png

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.
2018-01-15_100141.png

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.
2018-01-15_100317.png

In the resulting pop-up window we Name the Form and click Create to proceed to the Form Designer.
2018-01-15_100436.png

2018-01-15_100555.png

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.
2018-01-15_101558.png

2018-01-15_102407.png

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.
2018-01-15_103118.png

Then, we Edit Input Mapping for this step.
2018-01-15_103631.png

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.
2018-01-15_104022.png

Back in the Flow Designer we addTo 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 .
2018-01-15_104212.png

2018-01-15_104300.png

We select Show Mapping Editor option to map Data for the To Text step.
2018-01-15_104949.png

In the Mapping Editor we connect CreateStringBuilder_Output to the string builder field. Then, we click Ok to save and close Mapping Editor.
2018-01-15_105130.png

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 thisArray of Bytes as Contents for our New CSV file.
2018-01-15_105506.png

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.
2018-01-15_110149.png

2018-01-15_110925.png

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.
2018-01-15_111303.png

In the resulting pop-up window we Name the Form and click Create to proceed to the Form Designer .
2018-01-15_111429.png

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.
2018-01-15_112211.png

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.png

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

2016-12-16_145509.png

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.png

This completes our Flow . We click Debug Flow link on the top panel in the Flow Designer to test our Flow .
2018-01-15_115534.png

Our Form for adding new rows opens in the Debugger . We add new coma separated rows and click Done .
2018-01-15_115627.png

Then, our Download File Form opens in the Debugger . We clickDownload File…
2018-01-15_115644.png

Next, we Name our file and save it.
2018-01-15_120752.png

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.
2018-01-15_120902.png

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

2016-12-16_150709.png

Was this article helpful?