> For the complete documentation index, see [llms.txt](https://docs.appstrategy.com/apprules-r-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.appstrategy.com/apprules-r-documentation/samples/sample-projects/miscellaneous/custom-queries.md).

# Custom Queries

This sample project demonstrates how to define and use a custom query to read data records.

In the sample, instead of **configuring** selection options for the source, the appRules Custom Query Editor is used to define a simple query.&#x20;

Feel free to experiment with your own queries.

{% hint style="info" %}
The appRules Custom Query Editor supports SQL query access for all data sources.  This includes not only relational databases, but also SaaS platforms such as Salesforce, Dynamics365, Snowflake, etc.&#x20;
{% endhint %}

<figure><img src="/files/ylOcbAfkgGCkUDCZRwkl" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/v3HXGoNrQbF1WSj1XiRD" alt=""><figcaption></figcaption></figure>

**Points of interest:**

* **1 - InitializeSource Activity**

Select CustomQuery as the QueryType instead of Configuration.  Click the Add/Edit Query property to define the custom query:

<figure><img src="/files/iBvEYof7YenZKM0xf7n3" alt=""><figcaption></figcaption></figure>

* **2 - While Activity**

The While activity is used to loop through and view the resulting records. It has been configured with a condition to to end after reading the last record from the dataset.

* **3 - ViewRuntimeRecords Activity**

This activity has been configured to display the current record. In an actual project, the values can be used for loading additional data, calculations, etc.

* **4 - GetNextRecord Activity**

This activity gets the next record from the resulting dataset.


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.appstrategy.com/apprules-r-documentation/samples/sample-projects/miscellaneous/custom-queries.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
