Using A Flow To Fill A Data Store From The Database

Hey everyone…

I’ve just been playing around with Flows and Data Stores and I’ve managed to successfully fill a data store with contact records from my database, so I thought I would document what I did…

… both to help those looking to do the same thing…
… and to get feedback about whether I have done things in the most recommended way.

Best wishes,
Antony.

Step 1 - Server Action

Create a server action which gets all the contacts belonging to a “subscriber_user” of my system:

Step 2 - Data Store

I created a datastore called contacts and defined a variable in the store for each of the fields I want to store from the contact record:

datastore

Step 3 - Load Data Store From a Flow

So then I created a flow to load up the data store. A few points to note about this:

  1. The Data Store exists outside of the Flow. To execute something outside of the flow we use the Run => command.

  2. First we clear the Data Store, then we use a Server Connect inside the Flow to go and get the contact records from the database.
    We use the SC inside because the Flow waits for this to execute before continuing onto the next statements.

  3. Then we use a Repeat loop to repeat through the contacts returned from the Server Connect.
    Within each loop, we use a Run=> step to insert the value of the current contact record into the external data store.

flow

Step 4 - Viewing The Contacts

The contacts Data Store can then be used as the source of a repeat region:

<div dmx-repeat:rg_contacts_datastore="contacts.data">

Or in my case, I wanted to qualify the list of contacts by the is_a_test field being equal to a variable called test_mode:

<div dmx-repeat:rg_contacts_datastore="contacts.data.where(`is_a_test`, test_mode.value, &quot;==&quot;)">
5 Likes

PMed you @Antony , check when you are free, data store related!

Hi @Antony

Following your guide here, how did you manage to have output fields from the repeat?
It’s just empty for me.

More people seem to have that problem:

https://community.wappler.io/t/copy-database-table-record-to-data-store/18494/8

https://community.wappler.io/t/app-connect-flows-using-loops-etc/18111/13

Try saving the Action, closing the Action, then open it again, see if that displays the output fields. We have this issue occasionally… Seems sometimes it does not refresh automatically. Likewise with other items such as selecting Security Restrict rules/definitions…

1 Like

Unfortunately that didn’t work, but manually entering the output fields in code view works in case anyone has the same problem:

2 Likes