The Read From a Database action node in BRYTER serves the purpose of retrieving information from a database database and making it accessible as variables within your module.
Read in either one record via its ID, or read in multiple records and make them available in a collection. To createa a collection, you will need to filter the database and only read records that match your conditions. You can then sort the records within your collection.
Reading a single record
To read a specific record from a database created within the same application, create a Read From a Database action. Choose the database you have set up, then select Find a record as the read type and reference the record's unique ID.
By default, this action retrieves all database fields, storing them in a variable for use in subsequent nodes. To limit the retrieved fields to only what you need, uncheck the boxes in the OUTPUT section.
The record ID
You can obtain the specific ID of a database record through various methods:
- In most cases, record IDs are provided through a start parameter in a Data View action node and then are imported into your module via the START node.
- The Write to a Database action node generates a variable with the record ID, which you can reference in subsequent nodes.
- If your databae uses uses easy-to-use IDs, such as an email address, you can also ask the end user to enter the ID into a Text input node.
If you input an ID to retrieve a specific record from a database, there is the possibility that no record with that ID exists.
In such instances, all fields of the variable created by the Read From a Database action will be empty. This behavior allows you to establish conditions that respond appropriately to the action's output.
For example, you can configure a message to be displayed, such as No record found, whenever the record ID returned by the Read From a Database action is blank.
If you provide an ID that corresponds to a record in the database, some fields of the record might still be empty. In this case, those empty fields will be returned as blank.
Reading multiple records
To retrieve multiple records from a database, begin by creating a Read From a Database action. Follow these steps:
- Select the database from which you want to read data in the DATABASE field.
- Choose Filter records as the read type and confirm the conversion of your output variable to a collection.
- Use the Rule Builder to specify which records in the database should be read into your module and made available as a collection.
- Optionally, you can set up how how collection items should be sorted for presentation, whether in references or when adding them to a document's table. Configure sorting variables and choose the order (ascending or descending) within the SORTING field. You can also apply multiple sorting criteria as needed.
If none of the records meets the specified conditions, the collection generated by the Read From a Database action will be empty.
This means that when the collection is referenced in a text, nothing will be displayed. It also implies that when building conditions, all fields of all entries in the collection will be considered blank. This behavior allows you to build conditions that respond appropriately to the action's output.
For example, you can configure a message to be displayed, such as No record found, all IDs in the collection are blank.
Environment considerations
Read From a Database actions are environment-specific. When used in the Test environment, they retrieve data from the Test version of the database. In the Live environment or a client-specific environment, they access data from the corresponding Live or client-specific database.
For testing purposes, it is advisable to use the Test version of the database rather than the preview mode, as preview mode generates mock values for later use.
Related topics
- If you want to write to a database, use the Write to a Database action.
- If you want to delete records from a database, use the Delete From a Database action.
- If you want to use or reference entries in a MS Excel sheet in a module, you can upload the .XLSX file into a database and then read the uploaded data into the module.