database

Send data from an app

Updated: October 14, 2020

The best way to save data collected by your apps is to send it to a database. You can even send documents to a database.

How to send data

Sending data from your app is a relatively simple two-step process:

Step 1. Add a Send Data function to a Page Block

You send data from a Page Block using the 'Send Data' function: 

When you add a 'Send Data' function, you must select where you want to send the data to. When you select 'Workbase', you'll be prompted to select which Workbase (you can have multiple) and which table within that Workbase.

You can only send data AFTER you collect it
You can only send data that has been defined in prior Page Blocks. You can't send data from the same Page Block where it is being collected.

Step 2. Specify what data you want to send

You specify what data you want to send by adding parameters (or "params") to the 'Send Data' function. A parameter consists of two things:

  • Column name: The column in your Workbase table you want to send data to; and
  • Value: The value, typically a variable, you want to send.

Sending key values

The first param in your 'Send Data' function is for the key value in your table.

Remember, each Workbase table has a 'key column' and every row has a unique key value. This is necessary to allow you to "look up" specific rows (this is relevant when you want to pull data out of your Workbase).

You must send a unique key value unless you want to update an existing row. We recommend using the session_id value for this:

When someone uses your App, they create a "session." Every session has a unique ID that is encapsulated in the session_id variable. By using this variable as the key value of your Workbase table, you guarantee that each row in your table is unique.

You can also create your own key values by combining two variables to create a unique composite. For example, you could use an Expression Block to create a variable that is equal to client_name join with a space to Today.

How to update existing rows

Whether your 'Send Data' function creates a new row or updates an existing row depends entirely on the key value param.

If the key value param is unique (e.g. session_id), you will create a new row of data. If the key value is equal to a pre-existing row's key value, you will update that row.

Sending data in a Loop Section

You can add a 'Send Data' function within a Loop Section, which means every time the end-user repeats over the loop the App will add another row of data to your Workbase.

There are two challenges when sending data from within a loop:

  1. From which Block inside the loop do you send data? 
  2. What do you use as the key value param?

From which Block inside the loop do you send data?

This is an issue because you can only send data that has been defined in prior Page Blocks (you can't send data from the same Page Block where it is being defined). This means you need to add a Page Block to your loop whose sole purpose is sending data collected in prior loop Page Blocks, like this:

The Info Block sends data collected in the prior Question Block

What do you use as the key value param?

You want the key value param to be unique for each loop member, otherwise every time the end-user repeats the loop they will re-write their own data. This means that your key value must be a variable defined within your loop (anything else will not be unique across loop members).

Send all matching data

{{ Work in progress }}

Contact us for support

Talk to a real person, quickly. We're available 9am - 5pm EST.