How to update row data with Baserow forms

How to Update Row Data With Baserow Forms

Form data can be used to update a row. If a respondent fills out a form, we may want to update data in an existing row, instead of creating a new row.

Respondents can manage their own information via forms. For example, if a user inputs their contact details, this data can be changed using forms without access to the database. We will match an existing row in a pre-populated form to update that specific existing row.

What we will build

In this tutorial, we will manage a feature request process to keep track of in-demand features to provide a better user experience.

  • Create custom forms to collect and update data
  • Pair Baserow with n8n (or another automation platform)
  • n8n instance to configure a pipeline with:
    • A webhook trigger that listens for an event
    • A Baserow node to update the fields of an existing row when a new response is received

Now, let’s update rows with form submissions.

1. Create a Database

Log in to Baserow. If you haven’t already, create an account on a hosted baserow.io or a self-hosted instance.

We need to set up a workspace and add a database to the workspace. The first step is to create a workspace.

Next, create a new database within the workspace. To create a database from scratch, select ‘+ Create new’ and enter the database name as ‘Feature Requests’. Then click the ‘Add database’ button.

create a database

A default table will be created when you start from scratch.

The next step is to add tables. We will create two basic tables within the database.

2. Table A: Set up table to collect data

First, create a table that will contain the new features. This Features table will hold information about desired features, as well as the demand or appreciation for each of these.

The following fields will be added to the Features table:

Field name Field type
featureID Single line text
Title Single line text
Description Long text
Category Single select
Priority Rating
Initiate Date
Deadline Date
Completed Date
Prefilled URL Formula

Set up table to collect data

The Prefilled URL formula field combines the share form URL from the Update table (Table B) with the prefilled values of the row to be updated. Further details are provided in step 4 below.

Next, create a new form view to collect new feature requests. To create a form view in your table, click the existing view at the top of the table and select ‘Form +’ from the modal. Name the view then click ‘Add form’ to add a form.

create a new form view

Create a shareable link to share the form publicly by clicking the ‘Share form’ link at the top bar. The link can be shared to add a new submission to the database. A new form submission will create a new row in the Features table.

3. Table B: Set up table to edit data

Next, we want to link the requests collected to the Features table so that when a new update request comes in, it will copy and paste it into the row with a corresponding row ID.

First, duplicate the Features table without the row data. This Update table will hold information about existing features, with the same exact fields we want to update in the Features table.

To duplicate a table, click on the three dots  icon next to a table. Select the ‘Duplicate’ option from the dropdown. The grid and form views will be duplicated to collect update requests.

Rename this table as ‘Update’, then rename the featureID field as updateID. The updateID will contain the ID of the row to be updated.

Set up table to edit data

Navigate to the form view in the Update table and create a shareable link to share the form publicly.

create a shareable link

This table will contain updated entries. When a form is submitted, a new row will be added to the Update table.

4. Prefill & hide form fields

Next, we want to prefill and hide fields available in the Update form view. Forms can be prefilled to help the user fill in the form faster. You can use query parameters added to the public form URL to prefill a form with data.

The pre-filled values will pull the required data from the database. To prefill the Update form using data from the Features table dynamically,

  1. Copy the generated share link URL from the Update form view.

  2. Add the URL parameters to prefill the updateID in the format: ?prefill_<field_name>=<value>. You can add more fields to be prefilled automatically, e.g. the Title.

  3. To hide the updateID field from the form, prefix the query parameters with hide_. Note that this still exposes the info in the URL, but will hide the field from being edited.

    <form-URL>?prefill_updateID=<featureID>&hide_updateID
    

If you want to prefill multiple field types you can do so by adding & ampersand symbol between the values. For example,

  ?prefill_Priority=2&prefill_Category=Enterprise,Accessibility

5. Us Baserow formula field to refill dynamically

Create a formula field in the Features table and use the CONCAT function to combine the text from multiple ranges and/or strings. Paste the form URL generated above to the formula field in the Features table.

```
link(concat('<form-URL>?prefill_updateID=',field('featureID'),'&hide_updateID'))
```

> The Prefilled URL formula field in the **Features** table (Table A) combines the share form URL from the **Update** table (Table B) with the prefilled and hidden field values of the row ID to be updated.
> 

Prefilled URL formula field

When the prefilled formula-generated URL is clicked, the updateID will be populated with the featureID. To update a feature row, share the prefilled URL.

Next, we will use n8n, a workflow automation platform, to connect Baserow with other apps.

6. Automation: Add credentials to authenticate n8n nodes

Log in to n8n. There are different ways to set up n8n depending on how you intend to use it. Choose a preferred way to set up n8n.

Before you integrate an app or service with n8n, you need to add credentials that will be needed in the later steps. We need to set up these prerequisites. Learn how to add your Baserow credentials to n8n here.

integrate an app or service with n8n

Next, we want to set a trigger to listen for when a form is submitted.

Before we add our regular nodes, we want to set up a trigger to listen for the webhook. Webhooks allow you to send notifications whenever a new form response is submitted. By integrating your Baserow webhook with n8n, we make sure that every piece of data collected through your form goes directly to where it needs to be for you to do something with it.

7. Set up a webhook with n8n as a trigger

We want to pull in data from our Baserow table with the n8n Webhook node. n8n Webhook node is a Trigger node that serves as the starting point for an n8n workflow. It allows you to create webhooks that can be used to receive data from Baserow when an event occurs.

Add the webhook node to your new workflow. Search for ‘Webhook’ and add the trigger node to a new workflow. This starts the workflow when a webhook is called:

Add the webhook node to your new workflow

Clicking on the webhook node will reveal the parameters section to configure the node. Within this section, you can view the URLs for the webhook.

n8n recommends using a test webhook URL when creating or testing a workflow. This ensures that the incoming data can be viewed in the Editor UI, which is useful for debugging.

Choose the POST HTTP method. POST requests are typically used to send data to a resource for a create/update operation.

Choose the `POST` HTTP method

Copy the test webhook URL. Next, let’s put the test URL to use by making a POST request in Baserow.

We will create a webhook to call the n8n pipeline that generates the update.

8. Create a webhook in Baserow for form submission

Now that we have the webhook URL, we need to configure the application with this webhook URL to set up the trigger.

Go back to Baserow to create a webhook triggered on row creation. Webhooks can inform 3rd party systems when rows in Baserow have been created, updated or deleted.

Create a new webhook in the Update table. Select the method as POST and paste the webhook URL copied from n8n to receive requests. Select the events to trigger the webhook.

Create a new webhook

Back in n8n, click the ‘Listen for test event’ button.

While Listening for the test event on n8n, back in Baserow, click the ‘Trigger test webhook’ button on the webhook modal. You will receive a 200 OK response.

The Test webhook is only registered in the time between executing a workflow via the UI and until the first call gets made (when it displays “waiting for Webhook call”).

9. Get row with the Baserow node

We want to sync data to update the fields of the row identified by the ID. For example, if a respondent fills out update details, the data is populated in the Updates table then the automation will find the existing feature details in the Features Table and copy the data entered and input it into the corresponding row.

We want to search for the prefilled updateID in the Features table.

Search and add the Baserow node to the workflow:

Get row with the Baserow node

Click the Baserow node to reveal the parameters to configure. Within this section,

  • Select the credential for Baserow API configured to authenticate the Baserow node in n8n.

  • Select “Row” as the Resource

  • Select “Get Many” as the Operation

  • Select “Feature Requests” from the list as the Database to operate on, or specify an ID using an n8n expression.

  • Select “Features” from the list as the Table to operate on, or specify an ID using an n8n expression.

  • Map the search term to match as UpdateID. Click on ‘Expression’ to write the expression in the expression editor. Browse and select the updateID from the webhook data in the Variable selector.

    n8n expressions allow you to set node parameters dynamically based on data from a previous node. If you don’t see your webhook data, add a new row to the table then trigger webhook.

n8n expressions

Click the ‘Execute node’ button to get a response. The output will display the corresponding row in the Features table.

10. Update row with the Baserow node

We want to reference the ID and specify which fields to be filled or edited with the updated info from the row.

Add another Baserow node to the workflow. Configure the parameters:

  • Select the Credential for Baserow API configured
  • Select “Row” as the Resource
  • Select “Update” as the Operation
  • Select “Feature Requests” from the list as the Database to operate on, or specify an ID using an n8n expression.
  • Select “Features” from the list as the Table to operate on, or specify an ID using an n8n expression.
  • Specify the ID of the Features row to update using an n8n expression from the previous Baserow node. In this case: {{$node["Baserow"].json["id"]}}. Within the expression result pane, you can see the rendered result.
  • Data to Send: Define Below for Each Column
  • Add the fields to modify. Select the Field Name from the dropdown and specify the Field Value from the Webhook node using an expression.

Webhook node

Click the ‘Execute node’ button to get a response. The output will display the rows in the table.

The Baserow webhook will trigger on every event when a form is submitted and a new row is created in Table B. The updated row will sync with the same row ID in Table A.

11. Execute & activate workflow for production

To test the workflow, trigger the workflow manually by going to the canvas and clicking ‘Execute Workflow’. After you execute the workflow, you will get a response.

The test webhook URL only works for one call after you click the ‘Execute Workflow’ button on the canvas. After the Test webhook gets called for the first time, it displays the data in the Editor UI and then gets deactivated.

Execute & activate workflow for production

After the test, the next step is to save and activate the workflow. This workflow will run as defined once you activate it. Save the workflow and then click on the Active toggle at the top of the canvas to activate the workflow. Activating will ensure that the workflow will fire automatically each time the trigger condition is met.

Once you’ve finished building your workflow, run it without having to click the execute button by using the production webhook URL. When working with a Production webhook, ensure that you have saved and activated the workflow.

saved and activated the workflow

Your workflow will then be triggered every time a POST request is sent to the Production webhook URL.

Data flowing through the webhook won’t be visible in the Editor UI with the Production webhook. These executions will not show up immediately in the editor, but you can see them in the execution list if you choose to save executions.

Key takeaways

This workflow can be adapted to any use case. With batch create/update/delete rows endpoints, you can modify multiple rows at once.

A respondent can update submitted data. You can also specify when the information should be updated. For instance, whether to always update the information or only when it was previously blank.

Other tutorials:

In case you’ve run into an issue while following the tutorial, feel free to reach out to ask for help in the Baserow community.

What’s your use case? Tell us how you use Baserow