- 13 May 2020
- 3 Minutes to read
- Print
- DarkLight
Appending CSV File Using String Builder
- Updated on 13 May 2020
- 3 Minutes to read
- Print
- DarkLight
Overview
Appending CSV Files using a String Builder requires a few steps to get the data from the File and then create the information needed to Append a CSV File into Text. The String Builder steps are found in the Steps panel under Data > Text > Builder.
Example
This example demonstrates how to append new rows to a CSV file using String Builder steps. These steps can be found in the Data > Text > Builder category in the Steps panel.
Begin in the Designer Folder, select 'Create Flow' in the Folder Actions panel. Name the Flow and select 'Create' to proceed to the Flow Designer.
First, add Create Data step from Favorite Steps category in the Add After dialog.
In the Edit Step dialog, select 'Show Editor' to add a new Data Definition.
In the Data Definitions dialog, Name the data and define its Type as FileData.
Select 'Edit' under Input and choose a CSV file. Then select 'Close' to save and close this dialog.
To use the Text > Builder steps in the Flow a string builder needs to be created first. Add a Create String Builder step from All Steps [Catalog] > Data > Text > Builder category in the Add After dialog on the 'Done' outcome path from the Create Data step.
Because the contents of the CSV file is the Byte Array type, add a Get String From Bytes step from All Steps [Catalog] > Data > Text category to convert the CSV file contents into a string.
Select the Get String From Bytes step. In the Properties panel, under Inputs > bytes, choose File.Contents from the Flow.
Next, append the string from the CSV file to the string builder. Add a Append Line step from All Steps [Catalog] > Data > Text > Builder category.
Select the Append Line step. In the Properties panel, under Inputs > line To Add, choose GetStringFromBytes_Output from the Flow. Under Inputs > String Builder, choose CreateStringBuilder_Output.
Next, create a Form for the user to be able to add new rows. Add a Show Form step from Favorite Steps category in the Steps panel.
In the Pick or Create Form dialog, name the Form and select 'Create' to proceed to the Form Designer.
This Form has a Text Box Multi Line component from the Data category for users to input new Rows. The Form also has a Button named "Done". When finished designing the Form save and close Form Designer.
Next, add new rows from the Show Form step to the String Builder. Add the Append Text step from the All Steps [Catalog] > Data > Text > Builder category in the Steps panel.
Select the Append Text step. In the Properties panel, under Inputs > String Builder, choose CreateStringBuilder_Output from the Flow. Under Inputs > text To Add, choose New Rows from the Form.
Add a To Text step from the All Steps [Catalog] > Data > Text > Builder category in the Steps panel. This step retrieves data from the String Builder.
Select the To Text step. In the Properties panel, under Inputs > String Builder, choose CreateStringBuilder_Output.
Next, add Get Bytes From String step from All Steps [Catalog] > Data > Text category in the Steps panel. This step converts the string output from to To Text step into an Array of Bytes. The Array of Bytes will be available to use as contents for the New CSV file.
Select the Get Bytes From String step. In the Properties panel, under Inputs > str, choose ToText_Output.
Add a Show Form step from Favorite Steps category in the Steps panel. This Form will allow the user to Download the updated CSV file.
In the Pick or Create Form dialog, name the Form and select 'Create' to proceed to the Form Designer.
This Download File Form has a Button control from the Actions category named "Done". It also has a File Download component from the File Handling category. With this control, the user will be able to download the File that is mapped to this control. Save the Form and close Form Designer when finished.
Back in the Flow Designer, connect the 'Done' outcome from the Show Form Step to the End Step in the Flow. Select the Show Form step and navigate to the Properties panel.
Under Inputs > Download File select Build Data as the mapping type.
Next, connect GetBytesFromString_Output to the Contents field. Give the FileName a Constant name.
Debug
This completes the Flow. Select Debug in the top panel in the Flow Designer to test the Flow.
The Form for adding new rows opens in the Debugger. Add new comma-separated rows and select 'Done'. Then, the Download File Form opens, select Download File.
Next, name the file and save it. Locate and open the New CSV file and confirm that the new rows of data were added.