> For the complete documentation index, see [llms.txt](https://docs.octoxlabs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.octoxlabs.com/documentation/use-octoxlabs/queries/modify-existing-queries.md).

# Modify Existing Queries

Run, edit, duplicate, copy to other companies, organize in folders, export and delete saved queries.

Manage the saved queries of an inventory from one list: run a query, change its text, name or tags, make a copy, group queries in folders, export them or delete them.

### Before you begin

* Required permission: `queries.view_query` to open the list.
* You can edit or delete a query you own. To change or delete other people's public queries you need `queries.change_query` or `queries.delete_query`.
* Private queries are visible only to their owner.

### Open the Saved Queries list

In the left menu, select **Inventories**, open the inventory, and select **Saved Queries**. Each inventory has its own list, because a query always belongs to one inventory.

The table shows **ID**, **Name**, **Tags**, **Public**, **Updated at**, **Updated by** and **Count**. Use the **Search** box (press Enter) to filter by name, query text, description, owner or tag. At the end of each row there are icon buttons for the actions below. Select **List View** or **Folder View** in the selector above the table to change the layout.

### Run a saved query

Select the run button of a row. The inventory opens with the query text in the search box, and the label above the box reads "Editing" followed by the query name.

The run button with the tooltip **Run with saved columns & sorting** does the same and also applies the columns and sort order that were saved with the query. A plain run keeps your own columns.

While the label shows the query name, you can change the text in the search box and select **Save** next to it to write the new text back to the saved query. Select **Cancel** to leave the saved query as it is and clear the search box.

### Edit a saved query

{% stepper %}
{% step %}

#### Open the edit page

Select the edit button of the row. Only the owner and users with `queries.change_query` see it.
{% endstep %}

{% step %}

#### Change the query

On the "Query Edit" page you can change:

* **Name**.
* The tags. Select **Create tag** to add a new one: enter a **New Tag Name** and select **Create**.
* The query itself, in the Query Wizard. See Create and Save Queries.
* **Public**.

Select **Run Query** to test the change in the inventory before you save.
{% endstep %}

{% step %}

#### Save

Select **Save**. A message says "Query updated" and you return to the list.
{% endstep %}
{% endstepper %}

After you save, OctoXLabs recalculates the **Count** against the latest completed discovery, adds the query's tags to the assets that match, renames the chart rows that use the query, and refreshes the count of every query that includes this one with `Query is <query ID>`.

{% hint style="warning" %}
Other saved queries include a query by its ID, so a change to the text changes what those queries return. Charts, widgets, asset profiles, security policies, scheduled reports and workflows can also use the query. To see them, start a delete and read the dependency list (see Delete saved queries), then select **Cancel**.
{% endhint %}

### Duplicate a saved query

Select the duplicate button of a row. OctoXLabs creates a private query named after the original with " - Copy" added, and shows "Query duplicated as" followed by the new name. Only the name and text are copied. Edit the copy to add tags or make it public.

### Copy a query to other companies

If you administer more than one company, a populate button appears in each row. Select it to open **Populate** followed by the query name, choose the companies, and confirm. OctoXLabs copies the query to those companies, together with the queries it includes through `Query is <query ID>` and the tags attached to them. A query whose ID already exists in the target company is not overwritten.

### Organize queries in folders

Select **Folder View** in the layout selector to group queries in folders.

* **Create Folder** adds a folder. Rename it with the edit button of its row.
* Select queries, then **Actions** > **Move To Folder** to move them.
* Folders cannot be nested ("Nested Folders are not allowed.").
* Deleting a folder deletes every query inside it, after you confirm.

The export, download and populate actions are available in **List View**.

### Export and download

In **List View**, select rows and use:

* **Actions** > **Export Selected Items** to export the selected queries as a file. With no row selected, all queries are exported. Requires `users.export_import_data`. To import a file, see Export / Import.
* **Download** > **CSV**, **PDF** or **XLSX** to generate a Query Report for the selected queries. Requires a report permission.

### Delete saved queries

Select the delete button of a row, or select several rows and choose **Actions** > **Delete Selected**. In the confirmation:

* If nothing uses the query, confirm with **Delete**.
* If something does, the dialog lists the dependent items by category (**Queries**, **Charts**, **Widgets**, **Asset Profiles**, **Security Policies**, **Scheduled Reports** and **Workflows**). Select "I acknowledge the dependent items above will be affected." and then **Delete**.

A message confirms how many queries were deleted. Deleting does not remove the dependent items, they keep a reference to a query that no longer exists. A query that includes the deleted one with `Query is <query ID>` stops working and reports "Query not found. It's may be deleted."

### Troubleshooting

| Symptom or message                      | Cause                                                                   | Fix                                                                |
| --------------------------------------- | ----------------------------------------------------------------------- | ------------------------------------------------------------------ |
| The edit button is missing.             | You do not own the query and lack `queries.change_query`.               | Duplicate the query and edit the copy, or ask an administrator.    |
| A query is missing from the list.       | It is private and owned by another user.                                | Ask the owner to select **Public**.                                |
| "Query not found. It's may be deleted." | The query includes a deleted query by ID.                               | Edit the query and remove or replace the `Query is` condition.     |
| **Delete** stays disabled.              | The query has dependents and you have not selected the acknowledgement. | Select "I acknowledge the dependent items above will be affected." |

### What's next?

<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Create and Save Queries</strong></td><td>Build and save a new query.</td><td></td></tr><tr><td><strong>Query Examples</strong></td><td>Copy ready-made queries for common questions.</td><td></td></tr><tr><td><strong>Query Report</strong></td><td>Report on the results of saved queries.</td><td></td></tr><tr><td><strong>Export / Import</strong></td><td>Move queries between environments.</td><td></td></tr></tbody></table>
