Using Converters When Fetching Data From DatabaseLast Updated: 08/11/2016 Introduced in Verision: 2.0 |
Database entities represent external databases which can be integrated with a flow. To add a database within the portal, navigate to the folder System > Designers > Integrations > Databases, click the Add Databasebutton, and supply the necessary details. Once a database is introduced, components to query, insert, or update data to or from the database within the Flow Designer can be used. They are found under Integrations > My Integrations > Database > [Database Name] > [Table Name].
Example
Fetching Data from an external database in the flow can be hard to work with due to its type. There are several options designed by Decisions to handle this.
The first option is described in this article. We are going to register Converter Flow to convert the database specific type to Decisions’ native Account type Object.
For this example we integrated with dbo_entity_account table from decisions database.
First, we begin in a Designer Folder by clicking Create Flow to create a new flow.
Next, name the flow and click Create to proceed to the Flow Designer.
Flow Designer opens with Flow Designer Wizard on the workspace. In this Wizard we expand Integrations > My Integrations > Database > decisions2(Database) > dbo_entity_account (Table) category and select Get all from dbo_entity_account step. Click Add to add this element to our workspace.
Next, we type “foreach” in Wizard’s Search bar to search ForEach step. We select it and click Add to add it to our Flow.
Next, Flow Designer Wizard provides us with a new pop-up window where we can pick a collection for our ForEach step to process. We select entity_account_Result which is a collection gathered by our Get all step from the database table. We click Add to add this collection to ForEach step.
Next, we need to create a new form to display Accounts. In the Wizard we expand Flows, Rules, Forms and Reports > Forms [Interaction] category and select [Pick or Create Form] step.
This form was designed as follows to display one record at the time. The input data that is acceptable for this form is of Account type.
When we save and close Form Designer we can connect the steps in our flow and save it. Mention that ForEach step outputs Item that is of database specific type and our Form accepts Account type. We need to create converter flow to handle this. Close this flow.
Back in the Designer Folder click Create Flow to create a new flow.
Next name the flow. From Behavior dropdown list pick Converter Flow because we are creating converter flow. Click Create to proceed to the Flow Designer.
In the Flow Designer select start step. In the right panel locate Flow Input Data box and click Add New link.
We name the input data and define its type. For the type we search a specific type that outputs our database. Click Ok to save and close Input Data definition window.
Next, select end step on our workspace. In the right panel locate Output Data box and click Add New link.
We name the Outcome data and select Account type for it. When finished we click Ok to save and close this pop-up window.
Next, we connect start and end step, and select Show Mapping Editor for our end step.
In the mapping editor we expand accountIn and accountOut and map the fields as needed. When finished we click Ok to save and close Mapping Editor. This completes our Converter Flow so we can save and close it.
Back in the Designer Folder we locate our first flow and click Edit from its thumbnail.
We can see that our form has validation issues because the Item produced by ForEach step needs to be converted into Account type. We select Show Mapping Editor for our Form step.
When we map Item to Account we can see the error that tells us that two type are Incompatible.
If we click on this item’s mapping type we will see our converter flow as one of the mapping type options. We choose this option…
It automatically finishes our mapping. We click Ok to save and close Mapping Editor.
This completes our flow so we click Debug Flow link at the top panel of our Flow Designer to test our flow.
Note that in Decisions version 3.5 and above, you’ll need to click the Test Flow link to access the Debugger.
Our flow starts executing in the debugger and first Account shows up in our form.
After all Accounts showed up our flow successfully runs to the end step with no issues.