{"title":"TableRelation Property","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/properties/devenv-tablerelation-property/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/properties/devenv-tablerelation-property, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/properties/devenv-tablerelation-property","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Sets up a lookup into another table.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":2,"title":"Applies to","slug":"applies-to","at":493,"chars":39},{"level":2,"title":"Remarks","slug":"remarks","at":532,"chars":433},{"level":2,"title":"Example","slug":"example","at":965,"chars":2062},{"level":2,"title":"Related information","slug":"related-information","at":3027,"chars":94}],"text":"> Version: _Available or changed with runtime version 1.0._\nSets up a lookup into another table.\nThe following syntax is valid for the TableRelation property:\n```\nTableRelation = <TableName>[.<FieldName>] [WHERE(<TableFilters>)] |\n[IF(<Conditions>) <TableName>[.<FieldName>] [WHERE(<TableFilters>)] ELSE <TableRelation>]\n<Conditions> ::= <TableFilters> <TableFilters>::= <TableFilter> {,<TableFilter>} <TableFilter>::= <DestinationFieldName>=CONST(<FieldConst>) | FIELD(<SourceFieldName>)\n```\n## Applies to\n Table field\n Page Field\n## Remarks\nThe TableRelation property lets you establish lookups into other tables. For example, on the Item card you can select a vendor from who you usually purchase an item. This is done through a table relationship.\nThis property is also used to define where to look to validate entries.\nIn addition, when you choose the option to test the relationships between primary and secondary indexes, this property defines what to test.\n## Example\nThis example shows a simple application of the TableRelation property for creating a Vendors sub-table by filtering between the records to include only the ones where the purchase expenses are higher than 10,000.\n```al\ntable 50100 \"Main Vendors\"\n{\n  fields\n  {\n    field(1; \"Vendor No.\"; Code[20])\n    {\n      DataClassification = ToBeClassified;\n      TableRelation = Vendor.\"No.\" where (\"Balance (LCY)\" = filter (>= 10000));\n    }\n\n    field(2; \"Vendor Name\"; Text[150])\n    {\n      DataClassification = ToBeClassified;\n      FieldClass = FlowField;\n      CalcFormula = lookup (Vendor.Name where (\"No.\" = field (\"Vendor No.\")));\n    }\n  }\n}\n```\nMoreover, the TableRelation property can be modified through a table extension<../devenv-table-ext-object>. Modifications to the TableRelation are additive and evaluated after the existing value. The primary use case is conditional table relations based on conditional enums. The following example illustrates how to define first, an enum, and then a table setting a TableRelation.\n```al\nenum 50120 TypeEnum\n{\n  Extensible = true;\n\n  value(0; Nothing) { }\n  value(1; Customer) { }\n  value(2; Item) { }\n}\n\ntable 50120 TableWithRelation\n{\n  fields\n  {\n    field(1; Id; Integer) { }\n    field(2; Type; enum TypeEnum) { }\n    field(3; Relation; Code[20])\n    {\n      TableRelation =\n        if (Type = const (Customer)) Customer\n        else if (Type = const (Item)) Item;\n    }\n  }\n}\n```\nThe next code sample implements a table extension of the table defined above and an enum extension. The combined table relation is evaluated top-down. That means that the first unconditional relation will prevail, meaning that you cannot change an existing TableRelation from Customer to Item, since the original table relation is unconditional.\n```al\nenumextension 50133 TypeEnumExt extends TypeEnum\n{\n  value(10; Resource) { }\n}\n\ntableextension 50135 TableWithRelationExt extends TableWithRelation\n{\n  fields\n  {\n    modify(Relation)\n    {\n      TableRelation = if (Type = const (Resource)) Resource;\n    }\n  }\n}\n```\n## Related information\ndevenv-validatetablerelation-property\ndevenv-testtablerelation-property"}