Articles on: Dashboards & Jobs

How to Create SQL Calculated Attributes

Creating SQL-Related Attributes for Activities and Lists

This guide provides step-by-step instructions on how to create SQL-related attributes for activities and lists. These attributes are designed to automate calculations or update specific columns based on SQL queries.

Table of Contents

SQL-Related Attributes for Activities
SQL-Related Attributes for Lists

Steps to Follow:

Choose an Activity: Select the activity you want to add the SQL-related attribute to. For example, we will add the attribute in the retailer workflow activity.

Activity Selection

Choose or Add an Attribute:
- Select a question type based on the expected query result.
- For options like category_selected, use a single choice.
- For plain text (e.g., token number, date), use text.
- For integers, choose an integer type.
- In this example, we will use plain text to add the customer token number.

Attribute Selection

Add Question Title and Tag: In the overview section, add a title and tag for your question.

Question Title and Tag

Settings Tab:
- Go to the settings tab to add the SQL attribute.
Autofill Setting

- Before and after adding the SQL attribute, ensure the following options are set correctly:
a. Set 'Autofill Questions Answers' to 'Yes'.
b. Ensure 'Impossible to Change this Question' is set to 'Yes' for role-based access.

Change Restriction Setting

SQL Query:
- Add your SQL query in the provided format.
SQL Query
- Use meta expressions for preselecting values from a list. For example, to auto-select and associate the ID of a customer from the customer list and the token list, use a meta expression to add an expression that can retrieve the customer token number.

Meta Expression

- select the _id from the customer list and click next

Selecting Customer ID
- Optionally, set a default value.

Default Value

- Save changes for both the attribute and the activity.


Ensure that tags in queries with options match the single choice tags.

Steps to Follow:

Access Lists Section: Go to the lists section in the side panel. You can click on summary to view all the lists.

Lists Section

Choose a List: Select the specific list you want to add the SQL-related attribute to. In this case, we will use the customer list.

Choosing a List

Define the Attribute:
- Click on edit customer list and select the attribute you want to use by clicking on the add attribute button. For this example, we used an input text.
Add Attribute

- Add the title and tag for your customer list. For example, last retail audit date.

Title and Tag
Title and Tag Continued

SQL Query for Lists:
- To add an SQL attribute query, click on edit the attribute you have created.
- Click on the settings section, and you will see an option to add an SQL query. Consider various options before adding the query, such as hiding the attribute from the mobile app user, ensuring a unique value for this attribute, and locking the field to prevent non-admin users from changing the query.

Edit Attribute

- Use a query format that specifies the item to update and copy-paste it into the SQL section.

Example Query


You can wait for the hourly maintenance to update values or force maintenance in the settings for immediate effect (takes about 15 minutes).

By following these steps, you can effectively create and manage SQL-related attributes for both activities and lists, enhancing the automation and accuracy of your data management processes.

Updated on: 13/11/2023

Was this article helpful?

Share your feedback


Thank you!