Create Form to Write to a Database Table

Last Updated: 07/15/2016 Introduced in Verision: 2.0

This article will show you how to create a form that writes to a database table.

In this tutorial we will create a flow that lets us create new entries in a TV show database table. 

You’ll need to start with a designer project: http://decdocs3x.wpengine.com/creating-a-designer-project/

Because you want to read from a database or write to a database you’ll need a flow: http://decdocs3x.wpengine.com/creating-your-first-form/?display_cat=108

1. Add a form as a your first step to this flow.

Adding a Form to a Flow

Add a Form to the Flow

 

2. Add controls to the form to gather data.  We will need the following fields:

  1. Show Title
  2. First Year
  3. Number of Episodes
  4. Network
  5. Description
TV Show Form

TV Show Form

 

3. Now that we have a form that collects the data we need to get this data to the database.  

You can integrate with an existing database table: http://decdocs3x.wpengine.com/integrating-an-external-database-with-a-flow/?display_cat=114 

or you can create a new database stored type right in Decisions: http://decdocs3x.wpengine.com/simple-database-structure/?display_cat=131

For this example we will create a simple database type that looks like the screenshot below.  Please take note of the “Type Name” setting.  You will need this in the next step. 

DB Type

New Simple Database Type

NOTE: It’s very important that “Generate Flow Steps” is checked so that we automatically get a ‘Save’ step for use in the next step.

 

4. Put your flow back into edit mode by hitting the ‘Edit’ action.  

5. Browse to the ‘Integrations’ folder in the toolbox on the right hand side.  

6. Under ‘Integrations’ you should see a set of steps named after your ‘Type Name’ from step 3 above.  

Generated Steps

Generated Steps from Database Type Creation

 

7. Put the ‘Save’ step in your flow.  It will be invalid at first.

Save Step

Add Save Step as Invalid

 

8. To get all the data from the form into the Save step you can right click the Save step and choose ‘Show Mapping Editor.’  The mapping editor is NOT the only way to setup the data in the save step, but it is a great way to visualize different data types and map data from one type into another.  In this case we will use it to map the form data into the database table structure.  When you first open the mapping editor it will look like the screen shot below.

Mapping Editor

Empty Mapping Editor

 

9. On the right hand side you see a variable named ‘value’.  This is the new entry that will be written to the database.  Where the small orange text says ‘Unknown’ click, and change your option to ‘Build Data’.  Now you will see all the properties in your table.  

Build Data in Mapper

 

10. Drag lines from the fields on the left to the table structure on the right.

Mapped

 

11. Run your process and check the database for your results.

 

Additional Resources