Creating Queries

Creating queries to retrieve to dos from our database using the Query Desinger

In this section, we will create different queries to retrieve specific tasks from the database, namely :

For in-depth documentation about Queries, you can check out the corresponding documentation page :

Query Data

Creating a new Query

To create a new query, click on Query then click on New Query

Creating a new query

All Tasks Query

For this query, we simply want to retrieve all todos. We also give access to the Viewer group to run this query and access to the Editor group to modify this query.

In the Common Tab :

In the Fields Tab we can select which fields we want the query to return. For this tutorial, we will retrieve all the fields. Check the All checkbox on the right and click on Add Fields. This will populate our query with all the available fields in our To Do class.

We also want to sort the results of this query by having the latest task created first, so we sort the CreatedOn field in descending order by clicking on the Order By Descending Button.

In the Fields Tab :

All Tasks Query Properties

When done, click the Save button to save the query.

My Tasks Query

This query will only return tasks of which we are the owner and make use of Conditions.

In the Common Tab :

In the Fields Tab :

My Tasks Query Properties

Now we want to compare our user ID to the Owner field of the To Do class to determine if it should be retrieved or not. To add a new condition to our query, switch to the Conditions Tab, and click Add Condition.

On the right-hand side, choose the Owner field of your class. Click on the gear icon ⚙️ to open the Condition Properties window. Set Compare To to Expression and Value to {CurrentUser.ID}

My Task Query Condition Properties

Due Today Query

We want this query to return all to incomplete task due today. This means that we will once again make use of conditions to check both the IsCompleted and the DueDate fields of our To Do class.

In the Common Tab :

In the Fields Tab :

Due Today Query Properties

In the Conditions Tab, we click on Add Condition. Our first condition we want to check is MyToDos.IsCompleted = 0.

We now want to check if the due date is less or equal to today's date, which is denoted by MyToDos.DueDate <= {DateTime.Now.Date}.

To add a second condition, click on Add Condition and make sure to choose AND as the first connector Set the Field column to the MyToDos.DueDate field of your class set the middle Operator to <=.

Click on the gear icon ⚙️to open the Condition Properties window. Set Compare To to Expression and Value to {DateTime.Now.Date}

Due Today Condition Properties

Completed Tasks

For this last query we simply want to return completed queries.

In the Common Tab :

In the Fields Tab :

Completed Tasks Quey Properties

In the Conditions Tab, we click on Add Condition set the condition to MyToDos.IsCompleted = 1

Completed Tasks Conditions Properties

Last updated

Was this helpful?