Appending HTML Lines Using String BuilderLast Updated: 07/19/2016 Introduced in Verision: 2.0
This tutorial demonstrates how to use String Builder steps to Append HTML Lines. String Builder steps can be found under Data > Text > Builder category in the ToolBox.
In this Example we are going to create a Flow that retrieves Data from the database, and based on the Rule appends HTML Lines to the String Builder. Finally, our Flow is going to send an Email with a formatted text from the String Builder.
For this example we have integrated with Northwind database. We are going to use Data from Products table in this database. In order to integrate with external database please refer to this article: Integrating an External Database with a Flow.
First, we need to create a Rule for our future Flow. This Rule will check if we out of Product Items, and if we are, Product Information should be formatted with Red Font Color.
In the Designer Folder we click Create Rule > Create Rule from Folder Actions panel.
Next, we Name our Rule and click Create to proceed to the Rule Designer.
In the Rule Designer we click Add New to add new Rule Input.
In the resulting pop-up window we Name our Input and define its Type as Int16. Then, we click Ok to save and close this pop-up window.
Back in the Start Rule window we click Add New Rule Step to start designing our Rule.
In the resulting window we select our Rule Input (UnitsInStock [Int16]), and click Next to continue.
Then, we expand Equals category, select Is condition, and click Next to continue.
In the last Rule Step Configuration window we define Constant Value 0 and click Done.
Our Rule should be read as “If UnitsInStock Is 0”. If it is True, our Flow will format Product Information with Red Font Color.
We can save and close Rule Designer.
Back in the Designer Folder we click Create Flow from Folder Actions panel to create our Flow.
Next, we Name the Flow and click Create to proceed to the Flow Designer.
Every time we use Text Builder steps we need to create a String Builder first, and at the end we need to use To Text or To HTML Text step to retrieve data from the String Builder.
In the Flow Designer we add Create String Builder step from All Steps [Catalog] > Data > Text > Builder category in the Flow Designer Wizard.
Next, we add Get all from dbo_Products step from Integrations > My Integrations > Database > Northwind(Database) > dbo_Products(Table) category in the Flow Designer Wizard. This step was generated automatically by the System when we integrated with Northwind database.
Then, we add ForEach Step from All Steps [Catalog] > Flow Management category in the Flow Designer Wizard.
In the resulting pop-up window we need to pick a Collection for the ForEach Step. We select Products_Result outcome collection from Get all from dbo_Products step and click Add to continue.
At this point, a single Record from our Table is available in our Flow as an outcome from the ForEach Step. We need to check each Record in the Table using the Rule that we have created for this Example. On the Next outcome from our ForEach Step we add our Units In Stock Count Rule from Flows, Rules, Forms and Reports > Rules > [Current Folder] category in the Flow Designer Wizard.
On each (True, False) outcome from the Rule step we add Append HTMLLine step from All Steps [Catalog] > Data > Text > Builder category in the Flow Designer Wizard.
Then, we connect steps in our Flow in the following manner…
Next, we are going to configure Data Mapping for the steps in this part of our Flow.
First, we select ForEach Step on the workspace, and Step Information Layer pops up. In the Outputs section for the Next > Item we Rename outcome to SingleProduct.
Next, we select our Rule on the workspace and click Show Mapping Editor from the Step Options.
In the Mapping Editor we expand SingleProduct outcome from the ForEach Step and connect Value of the UnitsInStock field to the UnitsInStock Input for our Rule. Then, we click Ok to save and close Mapping Editor.
Back in the Flow Designer we call Mapping Editor for the Append HTMLLine step on the True outcome from the Rule step.
In the Mapping Editor we connect CreateStringEditor_Output to the data field. Then, we select Text Merge.HTML Mapping type for the lineToAdd field, and click Show Editor.
In the Text Merge.HTML Editor we use desirable fields from the Single Product Data to build an HTML string with the desirable information about the Product. Because this step connected to the True outcome from our Rule, current Single Product outcome will contain a zero Products in stock. We format Text color with Red Font Color. Then, we can close Text Merge.HTML Editor, and save and close Mapping Editor.
In the similar manner we configure Data Mapping for our second Append HTMLLine step that is on the False outcome from the Rule step. This time we format our Text with Green Font Color to indicate that these Products are available in the Stock.
Back in the Flow Designer we drag To HTMLText step from the Data > Text > Builder category in the ToolBox to the workspace. This step will retrieve data from the String Builder.
We connect To HTMLText step to the Done outcome from the ForEach Step and select Show Mapping Editor from its options.
In the Mapping Editor we simply connect CreateStringBuilder_Output to the data field. Then, we save and close Mapping Editor.
Finally, we add to our Flow Send Email step from the Favorite Steps in the Flow Designer Wizard.
Next, we connect Failed outcome from Get all from dbo_Products step and sent outcome from Send Email step to the End Step in our Flow. Then, we call Mapping Editor for the Send Email step.
In the Mapping Editor we define Constant Values for From, To, and Subject Fields. Next, we define Text Merge.HTML Mapping type for the Body field and click Show Editor to open Text Merge.HTML Editor.
In the Text Merge.HTML Editor we use Tohtmltext1 Output data to display all Products formatted according availability in the Stock. Then, we click Ok to save and close Text Merge.HTML Editor. Next we can close Mapping Editor.
This completes our Flow. We click Debug Flow link on the Top Panel in the Flow Designer to test our Flow.
Note that in Decisions version 3.5 and above, you’ll need to click Test Flow to access the Debugger.
In the Debugger our Flow executes with no errors.
We open received Email in the Inbox and confirm that all items that are Out of Stock are formatted with Red Font Color, while available Products formatted with Green Color.