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;)">
Community Page
Last updated: