bc_data_get_table_relations
Lists a Business Central table's outgoing and incoming TableRelation links, revealing join fields needed to write correct multi-table AL queries.
Instructions
Lists the TableRelation links of a Business Central table, so you can join tables correctly in an AL query. direction "outgoing" returns the tables this table points to and the fields that link them (e.g. Customer -> Country/Region via "Country/Region Code"); "incoming" returns the tables that point to this one (e.g. which ledger tables reference Customer), capped at 50 source tables with incomingTruncated/incomingTotalCount when cut. Conditional relations carry a "conditions" text (e.g. "Type=CONST(Item)").
Use it before writing a multi-dataitem query for bc_data_query: the via-field gives the DataItemLink. Pass relatedToTableIds to ask only about specific tables, which is also how to get past a truncated incoming list. Follow up with bc_data_get_table_schema for exact field names and types. When NOT to use: for single-table queries, or to read data. Runs on BC's own MCP server (BC 29+, "Data Query Tools (Preview)" enabled); needs no web-client session.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| 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. | |
| tableId | Yes | Numeric BC table ID (e.g., 18 Customer, 17 G/L Entry, 37 Sales Line). Find IDs with bc_data_find_tables. | |
| direction | Yes | "outgoing": tables this table points to through TableRelation fields (e.g., Customer -> Country/Region). "incoming": tables that point to this one (capped at 50 source tables). | |
| relatedToTableIds | No | Only relations to/from these table IDs. Use it to find the join path between two known tables, or when an incoming answer was truncated. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| hint | No | ||
| company | Yes | ||
| tableId | Yes | ||
| incoming | No | ||
| outgoing | No | ||
| tableName | Yes | ||
| incomingTruncated | No | ||
| incomingTotalCount | No |