bc_data_query
Compile and run read-only AL queries against readable Business Central tables, including extension tables without API pages, to fetch paged rows, joins, filters, and aggregations.
Instructions
Compiles an AL query object you write and, with returnData: true, runs it against any Business Central table the user can read — including tables with no API page and tables from extensions — and returns a page of rows. BC compiles the query on the fly as a dynamic object (nothing is published) and always runs it ReadOnly with the user's permissions and security filters. Without returnData it only compiles and returns the columns and dataitems, which is a cheap way to validate a query; compile errors come back as DATA_QUERY_ERROR with AL diagnostics (e.g. AL0345 for an unknown field) that you can fix and retry.
Workflow: bc_data_find_tables (table IDs) -> bc_data_get_table_schema (exact field names, for every table) -> bc_data_get_table_relations (join fields) -> bc_data_query. Joins, filters, aggregations (Method = Sum/Count/...), date grouping and OrderBy all work, so prefer letting BC aggregate over fetching raw rows. FlowFields can only be filtered with ColumnFilter, not DataItemTableFilter (AL0672). The bc-data-query skill has syntax and worked examples. Results are paged: top is 1-50 (default 10), skip pages forward, totalCount comes on the first page, hasMore says whether another page exists; rows are arrays in column order.
When to use: ad-hoc reads, totals and joins over data the Standard API does not expose, or when bc_query's entities do not fit. When NOT to use: to change data (read-only; use bc_write_data / bc_execute_action), for simple reads of Standard API entities (bc_query), or to see what a page shows (bc_open_page). Needs BC 29+ with "Data Query Tools (Preview)" enabled in BC's MCP Server Configuration, else BC_MCP_UNAVAILABLE (Microsoft has announced billing for these tools at general availability). No web-client session needed.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| top | No | Rows per page when returnData is true (default 10, max 50). | |
| skip | No | Rows to skip for paging (max 100000). totalCount is only returned on the first page (skip 0). Paging needs a deterministic order: add OrderBy if BC says pagination is not supported. | |
| company | No | Company to run in (exact, case-sensitive name from bc_list_companies). Defaults to the current session company, then BC_ODATA_COMPANY, then the user's default company in BC. | |
| queryText | Yes | Complete source of ONE AL query object, e.g. `query 50100 TopCustomers { elements { dataitem(Cust; Customer) { column(No; "No.") { } column(Name; Name) { } } } }`. Object ID and name are free (any ID works; nothing is published). Supports AL query features: joined dataitems (DataItemLink), filters (DataItemTableFilter on normal fields, ColumnFilter for FlowFields), aggregations (Method = Sum/Count/Average/Min/Max), date grouping (Method = Year/Month/Day), OrderBy. Limit rows with `top`, not TopNumberOfRows. Field names must match bc_data_get_table_schema exactly. | |
| returnData | No | false (default): only compile and return the column/dataitem schema — use it to check a query cheaply. true: also run it and return a page of rows. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| top | No | ||
| rows | No | ||
| skip | No | ||
| status | Yes | ||
| columns | Yes | ||
| company | Yes | ||
| hasMore | No | ||
| rowCount | No | ||
| dataItems | No | ||
| totalCount | No |