# Get Started with Query Designer

## Create a Query

Navigate to your **Workspace > Apps** and click on the gear icon <img src="https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MBCeOhqzSg8dBSFcJSA%2F-MBCo7T7BtG64Zwffv31%2Ffa-cog.png?alt=media&#x26;token=7b190f6b-19e5-4dea-8eaa-3bf0e53fa641" alt="" data-size="line"> to activate the configuration mode of your apps. Next, click on the gear icon <img src="https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MBCeOhqzSg8dBSFcJSA%2F-MBCo7T7BtG64Zwffv31%2Ffa-cog.png?alt=media&#x26;token=7b190f6b-19e5-4dea-8eaa-3bf0e53fa641" alt="" data-size="line"> of the app you want to configure. In the **Data** section you click on **Queries** to access the Query Designer. Click **New Query**.

![Create a new query in the Query Designer](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MA7JAoXQXUjLHXpzGzF%2F-MA7PPGDeka10-ew1gla%2Fnew-query.gif?alt=media\&token=88a5b256-06f7-465b-9931-fb178d608be6)

A query contains [*Common*](https://docs.tivity.one/building-an-application/data/query-data/query-designer-common) attribute&#x73;*,* [*Fields*](https://docs.tivity.one/building-an-application/data/query-data/query-designer-fields)*,* [*Conditions*](https://docs.tivity.one/building-an-application/data/query-data/query-designer-conditions)*,* and [*Default Values*](https://docs.tivity.one/building-an-application/data/query-data/query-designer-default-values). Use those properties to create data selections in order to provide information in your apps and reports.

## Common attributes

Every query needs some general information in the system. It is defined in the **Common** tab of the Query Designer.

1. Give your query a name and an optional description in the **Name** section of the designer. You can enter language-specific information for your query. In our example, we are creating a query to retrieve log entries.
2. Choose a **Source** to query data from and provide an optional **Query Context** in case you need to handle relations between multiple entities.
3. Select a value for **Run Credential** to define who will be able to see the result of the query. In comparison **Edit Credential** specifies who will be allowed to edit this query.
4. Optionally, you can specify whether the query is only used in other configurations and therefore **Invisible for users** and tick the option **Use as report** to limit access to the query.
5. In addition, you can use a **Pre-Script Configuration** to create a values in it's **script** which can be used for setting the condition of the query, before it has been executed.

![Specify the Common properties of a newly created query](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MBDlPn08bq0S_7Ys29D%2F-MBDs1UGNXRPeV82uU21%2FQuery_GettingStarted_Common.gif?alt=media\&token=f111beb9-546e-4350-8649-d91972216cc7)

## Fields selection

To display relevant information in your query you have to specify at least one field from the selected Source on the Common tab. Change to the tab **Fields**.

1. On the right-hand side you see the **Main Query Class** with a list of available entities to choose fields from.
2. Expand an entity to access a list of available fields to choose from. You can either choose to select *All* fields or tick individual fields from the entity. When done click on **Add fields**.
3. You can specify more properties of each field, ie. position, title, sort order, and handling of undefined values, in the list of Fields.
4. Optionally, you can add so-called **Virtual Fields** to your Query. Virtual fields are defined based on a **Script** and offer you a wide range of built-in functions to work with your data sources.

![Add Fields to a query and position them](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MBDlPn08bq0S_7Ys29D%2F-MBDs1UOpS3XDFmYCgRT%2FQuery_GettingStarted_Fields.gif?alt=media\&token=95fb90e4-2e30-4155-bc52-b2caa1b36178)

{% hint style="info" %}
You need to have at least one field to validate the query. You can add any number of fields to your query definition.
{% endhint %}

## Validate and Save a Query

Finally, click on **Validate** to verify that your selection of criteria is accepted by the Query Designer. Click on **Save** to store your query and return back to the list of queries in your app.
