Get Data Query
Audience:
Low-code EngineersSkill Prerequisites:
Actions,Listings,SQL
Stores the query behind a Listing's data source in tokens, together with the filters the user has applied. Use it to see what data the Listing is showing, for example to log it or reuse the filters in later actions.
It runs in Listing button actions and uses the search, filters and sorting sent with the button click. What the tokens contain depends on the data source type.
Typical Use Cases
- Debug a Listing by logging the exact query it runs
- Save the filters a user applied, for example with an export or a report request
- Reuse the Listing's filter clause in your own SQL, when the data source is a Database Table
Don't use it to
- Get the rows themselves. Use the built-in
ActionGridEntrylist on root buttons, or Run SQL Query. - Change the Listing's filters. Use Filter Listing instead.
Related Actions
| Action Name | Description |
|---|---|
| Run SQL Query | Runs SQL, for example to store the captured query or filters. |
| Filter Listing | Changes the sorting, paging and filters of a Listing. |
| Log Error | Writes a message, such as the captured query, to the log. |
Input Parameter Reference
Leave a parameter empty to skip that token.
| Parameter | Description | Supports Tokens | Default | Required |
|---|---|---|---|---|
| Store Query in Token | Name of the token that gets the data source's query, without the user's filters, for example DataQuery. | No | empty string | No |
| Store Filters in Token | Name of the token that gets the filters, such as search and column filters, for example DataFilters. | No | empty string | No |
| Store Filtered Query in Token | Name of the token that gets the query with the user's filters applied, for example FilteredQuery. | No | empty string | No |
Output Parameters Reference
| Token | Description |
|---|---|
[<Store Query in Token>] | The data source's query. |
[<Store Filters in Token>] | The current filters. |
[<Store Filtered Query in Token>] | The query with the filters. |
What the tokens contain
| Data source | Query | Filters | Filtered Query |
|---|---|---|---|
| Database Table | The start of a WITH Results AS (SELECT ..., ROW_NUMBER() OVER (ORDER BY ...) ... statement over the table. The ORDER BY follows the current sort. | A WHERE clause built from the filters, or empty when there are none. | The query plus the WHERE clause and the closing bracket. Add SELECT * FROM Results to run it. It isn't limited to the current page. |
| SQL Advanced Query | The data source's SQL query, with tokens replaced. | The filter expression. It isn't SQL. The Listing applies it in memory after running the query. | The query followed by -- filtered at runtime with: and the filters. The filters are only a comment. |
| Action Form (Obsolete) | The search index query. | The same search index query. | The search index query and the sort. |
| Other data sources, such as SQL Select or Server Request (JSON) | Empty. | Empty. | Empty. |
Considerations
- Listing buttons only. The action needs a Listing's context. It fails with
Data source not configuredwhen the Listing has no data source. - It may load the data. If the Listing's data hasn't been loaded in the current request, the action loads it first, so the data source's query runs.
- Not always runnable. Only the Database Table filtered query can be run as SQL. For SQL Advanced Query, filtering happens in memory, so the filtered query doesn't reflect the filters.
- Pass values safely. When you save a captured query or filters with Run SQL Query, pass them as bound parameters instead of pasting the token into the SQL.
- Doesn't stop execution. The next actions run normally.
Examples
To understand how to use the below examples, please see Running Examples.
1. Capture the Listing's query and filters
This action stores the query in [DataQuery], the filters in [DataFilters] and the filtered query in [FilteredQuery].
{
"Title": "Get Data Query",
"ActionType": "GetDataQuery",
"Description": "Capture the Listing's query and filters",
"Parameters": {
"OutputTokenNameQuery": "DataQuery",
"OutputTokenNameFilters": "DataFilters",
"OutputTokenNameFilteredQuery": "FilteredQuery"
}
}
2. Save the filters with an export request
Add this action after the one in example 1, on the same root button. It records who requested the export and which filters were applied.
{
"Title": "Run SQL Query",
"ActionType": "RunSql",
"Description": "Save the export request",
"Parameters": {
"SqlQuery": "INSERT INTO ExportRequests (UserId, Filters, RequestedOn) VALUES (@UserId, @Filters, GETDATE())",
"BindTokens": [
{ "name": "UserId", "value": "[User:UserId]" },
{ "name": "Filters", "value": "[DataFilters]" }
]
}
}
Revised 09/26/2026