> For the complete documentation index, see [llms.txt](https://docs.avonnicomponents.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.avonnicomponents.com/flow/tutorials/components/calendar/using-a-query-data-source.md). Agents can also search and read this documentation through its [MCP server](https://docs.avonnicomponents.com/~gitbook/mcp).

# Use a Query data source

Point the Avonni Calendar at Event records with a Query data source, filter and sort the visits, and refresh the calendar after a change.

A dispatcher wants the week's visits straight from Salesforce, without building Get Records elements first. With a Query data source, the Avonni Calendar reads the `Event` records itself, draws one row per technician from a lookup, and can query again when something changes.

<figure><img src="https://27923732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1FUd4apB9YHgCEMUFbVb%2Fuploads%2Fb23dXQtiQoImCSi8k1qy%2Fcalendar-using-a-query-data-source-result.png?alt=media" alt="Avonni Calendar timeline loaded by a Query on Event, with one row each for Michel Chartrand, Celia Desjardins and Hubert Michaud-Dufour drawn from the Technician lookup"><figcaption><p>The calendar queries Event itself and draws one row per technician from the lookup.</p></figcaption></figure>

## Before you start

* You have placed an Avonni Calendar on a flow screen. If not, follow the [Calendar 101](https://docs.avonnicomponents.com/flow/tutorials/components/calendar/calendar-101-tutorial.md) up to the data source step.
* To get one row per technician, `Event` needs a lookup to **User** that holds the technician, for example a custom field labelled **Technician**. **Assigned To** (`OwnerId`) can point to a user or a queue, so it cannot draw the rows.
* To compare the two data sources first, read [Understanding Data Sources](https://docs.avonnicomponents.com/flow/component-builder/data-sources/understanding-data-sources.md).

## Steps

{% stepper %}
{% step %}

### Choose Query and pick the object

1. In the **Properties** tab, open the **Data Source** section and select **Query**.
2. In **Object API Name**, pick `Event`.

Query mode has no separate resource collection: the rows come from the events themselves, through the **Resource Name** mapping set in a later step.
{% endstep %}

{% step %}

### Load only the visits you plan

Still in **Data Source**:

1. In **Filters**, add a condition on `StartDateTime` so only the planning period loads, and one on the event type if the team logs other activity as events.
2. In **Order By**, pick `StartDateTime` and set **Direction** to ascending.
3. In **Maximum Number of Records**, enter a number above the most visits a week can hold, for example `500`.

<figure><img src="https://27923732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1FUd4apB9YHgCEMUFbVb%2Fuploads%2F2ofuWtgOJ3ibSlkX7d1j%2Fcalendar-using-a-query-data-source-panel.png?alt=media" alt="Calendar Properties tab with Data Source set to Query on Event, two filters on Start Date Time and Technician, Order By Start Date Time ascending and Maximum Number of Records 500" width="320"><figcaption><p>Filters, Order By and Maximum Number of Records sit under the Query data source.</p></figcaption></figure>

{% hint style="warning" %}
Records past **Maximum Number of Records** are not loaded, and nothing on the calendar says so. If visits go missing on a busy week, raise the limit or tighten the filters.
{% endhint %}
{% endstep %}

{% step %}

### Map the events and their technician

In the **Data Mappings** section:

1. **Title**: `Subject`.
2. **Resource Name**: the **Technician** lookup. Because it is a lookup, a **Resource** group appears under it.
3. In **Resource**, set **Label** to the technician's name (`Name` through the lookup). Leave **Key Field** on its default, the record ID. Add **Avatar Source** if you want photos on the rows.
4. **From**: `StartDateTime`. **To**: `EndDateTime`.
5. Leave the event **Key Field** on the record ID.

If **Resource Name** is empty, every event is drawn under a single resource.
{% endstep %}

{% step %}

### Set the advanced query options, if needed

The **Data Source** section also has options under its advanced settings:

| Setting                       | What it does                                                                                          |
| ----------------------------- | ----------------------------------------------------------------------------------------------------- |
| **Additional fields**         | Loads fields the mappings and interactions do not use, for example to show them in **Popover Fields** |
| **Strip Inaccessible Fields** | Removes from the results the fields the running user cannot access                                    |
| **System Mode**               | Runs the query in system mode                                                                         |

Leave them off unless you need one.
{% endstep %}

{% step %}

### Refresh the calendar after a change

A query runs when the screen loads. When the dispatcher changes a visit from the calendar, for example in a flow opened with **Open Flow Panel**, the calendar still shows the old version until it queries again.

1. Open the **Interactions** tab and select the interaction that changes records.
2. Add **Refresh Query** as the next interaction, so it runs when the flow panel finishes.

[Refresh Query](https://docs.avonnicomponents.com/flow/component-builder/interactions-panel/refresh-query.md) works on Query data sources only. A Variable data source does not refresh this way.
{% endstep %}

{% step %}

### Save and test

Save the flow and run it with **Debug**. The calendar opens with one row per technician, labelled with the name from the **Technician** lookup, and the filtered visits in start time order. Change a visit through the flow panel: when the panel closes, the calendar reloads and shows the new time.
{% endstep %}
{% endstepper %}

## Related tutorials

* [Calendar 101](https://docs.avonnicomponents.com/flow/tutorials/components/calendar/calendar-101-tutorial.md): the same calendar with a Variable data source.
* [Connect multiple data sources](https://docs.avonnicomponents.com/flow/tutorials/components/calendar/how-to-connect-multiple-data-sources-to-the-avonni-calendar.md): show visits and work orders together.
* [Reschedule events with drag and drop](https://docs.avonnicomponents.com/flow/tutorials/components/calendar/how-to-reschedule-events-with-drag-and-drop.md): save a moved visit with Update Records.
* [Troubleshoot resources and missing events](https://docs.avonnicomponents.com/flow/tutorials/components/calendar/troubleshoot-resources-and-missing-events.md): when a row reads Empty or visits are missing.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.avonnicomponents.com/flow/tutorials/components/calendar/using-a-query-data-source.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
