The use and options of the Update record step in Actions.
After reading this article, you’ll know the following:
-
What the Update record step is and its purpose
-
How to use this step in your application
What is the Update record step?
Update record is a CRUD action step that allows users to modify existing records in their database by assigning new values to an object's properties and relations. This can be done using static values or dynamically by applying variables.
Imagine a healthcare application where patients can update their contact information. When a patient submits a form with their new phone number and email, the Update record action step retrieves the current patient record using their patient ID and maps the new contact details from the form submission to the respective properties of the patient record.
With the Update records step, you can easily update the property values of a specific record in your database. The step can be configured to update a record either through static values that are manually inputted or dynamic values that are derived from variables within the platform.
Options
Record: select the specific record that you want to update. You can choose a record using the variable picker, which provides access to all available record variables within the current scope.
Value mapping feature enables you to map new values to the properties of the selected record. These values can be either static, where you manually input the values, or dynamic, where you use variables. The new values provided will overwrite the existing values in the record.
As option allows you to define a variable name for the updated record. By naming the variable, you can easily reference and reuse the updated record in sub-action steps within your action.
Variables: In this separate tab, you can add more variables to the step, which can be used for dynamic value mapping. This is particularly useful when the values that need to be assigned depend on other variables or calculations within your application.
Use case - Update form component
One of the simplest and most effective ways to use the Update record action step in Betty Blocks is through the Update form component in Pages. This component simplifies updating records by automatically creating the necessary action with the Update record step.
Suppose you have a list of projects that you want to be able to update. Start by dragging the Update form component onto your page canvas. Configure it as follows:
-
Decide if the data should come from another page or this page. For example, if you're updating project details from the same page, choose 'This page'.
-
Select the model: Choose the Project model from which you want to display and update data.
-
Select properties: Select the properties of the project model that you want to display in the form, such as project Name, Description, and Status. These properties
Adding the Update Form component automatically generates a new action with a pre-configured Update records step. To customize this action:
-
Navigate to the Update form and open its options.
-
Click on the pencil icon to edit the action attached to this form.
3. In the Update record step, you will find that the fields are already filled with the appropriate values, mapped to the form inputs. This pre-configuration saves time and ensures consistency in updating records.
Use case - Condition flow result
Another use case for the Update record step is within a flow that includes a Condition step. For instance, in managing email configurations, you can use the Condition step to check if an email configuration record exists in the database.
If it exists, drop the Update records step to the True flow to update the existing record with new values, which you fill in yourself in the Value mapping section (e.g., Port, Username, Password, Hostname). If it doesn't exist (Else flow), the Create records step creates a new email configuration record. This ensures that email configurations are either updated or newly created as needed.
This setup is only one instance of multiple variations you can create on your own using the Update records step.
If you need to work with updating a lot of records at the same time, try looking into Update many records step from our Block Store.