Retrieve record
Learn how to use the retrieve record operation on your table by using a gym bot example
Last updated
Learn how to use the retrieve record operation on your table by using a gym bot example
Last updated
Retrieving a record from your table means that it allows bot query and retrieve information from an existing record.
To exemplify this, we will use a gym booking bot that uses a Table to retrieve information about available gym classes from the table, enabling users to view and select classes to book.
This means that from a table like this, you'll be able to retrieve only specific records, e.g. only the Zumba classes:
Zumba
Jenny
None
Yoga
Sergine
None
Zumba
Chloé
None
Retrieve record is an operation which doesn't edit your table. It just filters out which records we're looking at inside a conversation. It's usually combined with another operation, e.g. retrieve a record then update a record.
To retrieve a record:
Make sure that you have a well-defined table. For this example, we'll use gym booking table with those fields:
ClassName: Name of the fitness class.
ClassDay: Date of the class, in a consistent format (e.g., YYYY-MM-DD).
ClassTime: Start time of the class, using a clear format (e.g., HH:MM AM/PM).
ClassTeacher: Name of the instructor leading the class.
IsBooked: Status field indicating whether the class is booked ('None' or 'Available' by default, updated to customer's name upon booking).
Determine the point in your bot flow where users will request to view available classes. For this example, after users selected which class they want to book, a retrieve record operation will happen so that the bot finds that class in the table.
Add a Table operation to your flow at the point that you've defined.
Choose Retrieve record from the list of operations.
Select the table that you want to update. For this example, we'll select Gym class booking.
Under the Operation config section, click on + Add filter to set up the query to filter records based on the value(s) or one or more column(s). For this example:
We filter out by looking at the isBooked column. If the isBooked cell equals None, it means that the class is available for bookings. It means that we'll only retrieve classes that are available.
Additionally, we incorporate a filter for className to match the user's selection, ensuring that the query returns classes that align with the user's preference. It means that if the user is interested in yoga classes, then we'll only retrieve yoga classes and not other ones.
Under Limit, set a limit to the number of query results. In this example, we'll limit the results to 2. This ensures that the bot displays a concise list of available classes for the user to choose from.
If you need to skip a few numbers of records from your retrieve operation, fill in the field under Skip. For this example we won’t allow to skip the first number of records from results, so no need to do anything there.
Under Destination variable, assign the retrieved results to a variable. For this example we'll name it available_class
. This variable will keep retrieved classe(s) to use them inside the conversation.
Click Save.
Above, you've learned how to retrieve records from a table, which in this example are available gym classes. To display those retrieved records in the conversation:
Introduce a new Message block designed to let users pick from the available classes. This block serves as the juncture where users can visually see and select their preferred class timing.
For this example, let's call this block Display classes.
Add a Buttons step.
To concisely convey class availability, format your button titles to include the day and time of each class. Use the {variableName[index].values.fieldName}
variable structure to embed the retrieved class information:
{available_class[0].values.classDay} at {available_class[0].values.classTime}
.
As a practical example, if the first returned class is on a Monday at 10 AM, your button might be titled "Monday at 10 AM".
Given that we've set the operation to return up to two classes, ensure your message includes a button for each available option. Duplicate the formatting approach for the second button, substituting [0]
with [1]
to access the second item in the array:
{available_class[1].values.classDay} at {available_class[1].values.classTime}
This ensures both options are presented for user selection.
Click Save.
It's crucial to check the functionality of your Retrieve record operation to ensure data is retrieved and displayed correctly. Use the bot's emulator or a live test environment to simulate user queries for available classes.
Verify that the bot retrieves and displays the correct class information based on the availability in the table.
Looking for a quick and easy bot template to play with Tables? The Gym bot is a representative use case.