Advanced Text Merge Using the NVelocity Component

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

 A use case for this functionality could be to create a standardized letter or to replace text within existing documents that need updating.

Example

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.

01.-csv_file_result.png

We will begin in a Designer Folder by clicking the Create Flow button.

createFlow

 

In the resulting New Flow pop-up, we will name our flow “Get CSV of Folders Flow” and click OK.

nameFlow

 

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.

 

 flowStarts

In the Data Definitions section, we will click the Add button and define an output called “CSVRows” with a type of String.

defineCSVRows

 

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.

dragGetAll

 

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.

dragForEachStep

 

In the Properties tab, under the Collection section, we will open the Type selector and define a collection type of Folder.

defineCollectionTypeFolder

 

To iterate through our collection of folders, we will map the output of the Get All component to the Collection input.

mapGetAllToForeach

 

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.

dragCustomMerge

 

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.

showMappingForCustMerge

 

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.

mappingForCustMerge

 

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.

dragCreateTextFile

 

In the Mapping Editor, we will define our new file’s name as “FolderCSV.csv” and its data as CSVRows.

mappingCreateTextFile

 

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.

dragLoadFile

 

In the Mapping Editor, we will define fileName as “folderCSV.csv”.

mappingToLoadFile

 

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.

dragForm

 

In the Mapping Editor, we will define FileName as “FoldersCSV.csv” and map the output of the Load File component to FileForDownload.

mappingForForm

 

This completes our flow, so we will save it and close the Flow Designer.

saveFlow

 

Back in our Designer Folder, we will select Get CSV of Folders Flow and select Run Flow from the actions menu.

runFlow

 

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.

result

 

When we open the downloaded CSV file, we will see that it contains rows for every folder in our system.

22.-csv_file_open.png

Additional Resources