Advanced Text Merge Using the NVelocity ComponentLast Updated: 08/11/2016 Introduced in Verision: 2.0
NVelocity is an open source java template engineering framework. The Custom Merge [NVelocity] component allows variables to be merged with text in a defined template. These templates can be used to generate CSV data, HTML, XML or other forms of structured text.
In our example flow, the Custom Merge [NVelocity] component will generate a CSV file containing a list of folders. We will then display a form with which the user will be able to download the CSV file that was just created. This example assumes that this form “Download Folders CSV Form” has already been designed.
We will begin in a Designer Folder by clicking the Create Flow button.
In the resulting New Flow pop-up, we will name our flow “Get CSV of Folders Flow” and click OK.
We will first create the String which will contain our CSV file data. We will find the Create or Copy Data component in the Flow Designer’s start-up window, under the category All Steps [Catalog] > Data. Click Add to add it to the workspace.
In the Data Definitions section, we will click the Add button and define an output called “CSVRows” with a type of String.
Next, we will retrieve all of the folders in our system. We will find the relevant Get All component in the Toolbox tab, under the category Integration > Internal Services > FolderService.
Next, we will iterate through the folders we’ve retrieved. We will find the ForEach Step component in the Toolbox tab, under the category Flow Management.
In the Properties tab, under the Collection section, we will open the Type selector and define a collection type of Folder.
To iterate through our collection of folders, we will map the output of the Get All component to the Collection input.
For each folder retrieved, we would like to merge certain form properties into a CSV row and add it to the rows already defined. We will find the Custom Merge [NVelocity] component in the Toolbox tab, under the category Data > Text.
Our template will begin with the CSV rows that have already been defined. On the second line, it will contain each folder’s entity name, date of creation and short type name all comma-delimited. Once we’ve defined our template, the inputs necessary for populating these dynamic variables will be automatically generated.
In the Mapping Editor, we will map CSVRows to CSVRows. We also map the CreatedOnDate, EntityName and FolderTypeName properties of each Folder item to the appropriate input. We will also rename the output to “CSVRows”, so that each iteration aggregates the new row with the old ones.
Next, we would like to create the CSV file containing our CSV rows. We will find the Create Text File component in the Toolbox tab, under the category Integration > File.
In the Mapping Editor, we will define our new file’s name as “FolderCSV.csv” and its data as CSVRows.
Next, we would like to make this file available for download in a form. To do this, our flow will need to load the file back into the flow. We will find the Load File component in the Toolbox tab, under the category Integration > File.
In the Mapping Editor, we will define fileName as “folderCSV.csv”.
Next, we would like to display the form with which we’ll download our CSV file. We’ll find Download Folders CSV Form in the Toolbox tab, under the category Forms [Interaction] > [Root Folder] > Designer Entities.
In the Mapping Editor, we will define FileName as “FoldersCSV.csv” and map the output of the Load File component to FileForDownload.
This completes our flow, so we will save it and close the Flow Designer.
Back in our Designer Folder, we will select Get CSV of Folders Flow and select Run Flow from the actions menu.
In the resulting pop-up, we will be shown the Download CSV of Folders form. We will click the Download File button to download the CSV file that was created by our flow.
When we open the downloaded CSV file, we will see that it contains rows for every folder in our system.