# Query Designer

## Introduction

Query Designer enables you to manage queries and define the data selection from your database. Queries are composed of a data source (what you're inspecting), a field selection (what information you want to see) and conditions (what you're looking for). In this article we will introduce you to the flexible features of the Query Designer.

## Manage Queries

You can edit, delete, and clone queries, or export your query definition for use in another app. Head 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, navigate to the app you want to configure 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">. In the **Data** section you click on **Queries** to access the list of existing queries.

![Access the Query Designer in your apps](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MBCof6waLqDLg_Jk7RL%2F-MBDJm-NfgMV2SP-3eaM%2FQueries_Launch.gif?alt=media\&token=888144ce-c88a-4cc6-ae5f-64ac73b33f90)

### Create a Query

Click on **New Query** to create a new definition of how to select and display data in your application. [Get Started with Query Designer](https://docs.tivity.one/building-an-application/data/query-data/get-started-with-query-designer) describes the process of creating a query in detail.

### Edit a Query

Click on the query name from the list to open the query designer. The remaining functionality is identical to creating a new query, as described in [Get Started with Query Designer](https://docs.tivity.one/building-an-application/data/query-data/get-started-with-query-designer).

![Edit a query and validate before saving](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MBCof6waLqDLg_Jk7RL%2F-MBDJm-LX3_YLP-L83F1%2FQueries_Edit.gif?alt=media\&token=b27d772c-5398-4c3f-91c6-2785826225be)

Modify your existing query as needed, optionally **Validate** the current definition, and click **Save** to store your changes.

### Delete a Query

Either you open the drop-down menu on the right-hand side to the query name and choose **Delete** or you click on the query name from the list and click on **Delete** to remove the query.

![Delete a query from your application](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MBCof6waLqDLg_Jk7RL%2F-MBDJm-KR4gFhiU86YpP%2FQueries_Delete.gif?alt=media\&token=e430ee12-23b5-44d6-afcc-205c1829e60f)

Confirm to delete the selected query with a click on **Yes, delete it**.

### Clone a Query

In scenarios where you need the same query with minimal variations you don't have to create each query from scratch but you can duplicate an existing one. Open the drop-down menu on the right-hand side to the query name from the list and choose **Clone**.

![Duplicate an existing query to speed up multiple configurations](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MBCof6waLqDLg_Jk7RL%2F-MBDJm-59J4SoUySTcO2%2FQueries_Clone.gif?alt=media\&token=1285de71-4431-43c6-b593-d9a8c5fc889e)

After a short while a new query with a `- Copy` suffix will be added to the list of queries. You can create multiple copies of the same query.

{% hint style="info" %}
Prior to be able to clone a query it has to be validated successfully. If the copying process fails, open the query for review and validate it.
{% endhint %}

## Used By

Apart from being able to create and manage queries it is interesting to know whether and how a particular query is used in an application. Open the drop-down menu on the right-hand side to the query name in the list and choose **Used By**.

The Query Designer shows you in which Layouts, Classes, Functions, Selections, Templates, and Workflows the selected query is used.

![Used By provides you information where a query has been used](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MBCof6waLqDLg_Jk7RL%2F-MBDYLb3GWEMTsy9iEdj%2FQueries_UsedBy.gif?alt=media\&token=3a601637-8b6b-4c85-a02a-1cf4daa751e2)

Click on **Close** to return back to the list of queries.

## Export queries

To save your queries for backup or to transfer queries between applications and workspaces you would export them. Open the drop-down menu on the right-hand side to the query name in the list and choose **Export**.&#x20;

![Export your queries for backup or for use in other applications](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MBD_CKL1w03WrL1Au2r%2F-MBDjCiCUo29voC3jc62%2FQueries_Export.gif?alt=media\&token=7b4520a6-d29b-4177-a387-6cd4739d53b5)

The platform is going to assemble a ZIP archive and will offer you to download it to your system. The default file name is `queries.zip`.

{% hint style="info" %}
The generated ZIP archive is potentially password-protected.
{% endhint %}

## Import Queries

{% hint style="danger" %}
ToDo: Import fails due to invalid format of previously exported queries file.
{% endhint %}

Navigate to your **Workspace > Apps** and click on the gear icon to activate the configuration mode of your apps. Next, click on the gear icon of the app you want to configure. In the **Data** section you click on **Queries** to access the Query Designer. Click **Import Queries**.

Next, either drop an exported file from your system into the designated area or click on one of the available options to import your queries. Click **Execute** after the file has been uploaded completely.

![Import of queries to transfer definitions between apps](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MBEYyKjJ1pqnQwKX2eY%2F-MBEPDVsEjwDY2uIP5u5%2FQueries_Import.gif?alt=media\&token=7ece9089-84fa-4e14-affb-2683f1123f78)

After successful import the queries either have been created as new entries based on their original name or the suffix `- Copy` has been added to any existing query to avoid name conflicts.

## Grouping of Queries

Depending on the amount of queries the overview might become a crowded place with lots of entries. The Grouping feature enables you to organise your queries by a specific criteria, e.g. by First Letter (default) or by Last Modified date.

To change a grouping of queries click on the **Actions** <img src="https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MBCeOhqzSg8dBSFcJSA%2F-MBCnllzlzaz9n1FnXzP%2Ffa-ellipsis-h.png?alt=media&#x26;token=acaa46a1-e211-4b6d-8b0b-0d119b9b55d4" alt="" data-size="line"> menu at the top right of the list and choose an option. The list will be arranged immediately.

![Various options to display the list of queries](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MBCof6waLqDLg_Jk7RL%2F-MBDJm-MO7gNqVEHg8qV%2FQueries_Grouping.gif?alt=media\&token=33e409d2-b785-4ebc-bcf9-7f1b82f93021)

## Return to the Workspace

After you completed your changes in the Query Designer you scroll down to the bottom of the **Config Mode** in the left-hand side Workspace pane and click on **Leave Config Mode**. Then you click on the tick next to the **Apps** caption to return to your Workspace.

## More on Query Designer

Query Designer is a powerful tool to level up your apps, and with such power comes complexity. Take a look at some of our other articles about the different sections in the Query Designer for even more help.

* Query Designer's [Common](https://docs.tivity.one/building-an-application/data/query-data/query-designer-common) attributes, [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) provide you with an insight into the detailed definition of your queries.
* [Query Designer Preview](https://docs.tivity.one/building-an-application/data/query-data/query-designer-preview) offers the resulting data of your query to verify the expected information.
* [Script Configuration](https://docs.tivity.one/building-an-application/execution/scripting) has further details on built-in functions and how to create and manage your own scripts.
