{"title":"Report Extension Example","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/devenv-report-ext-example/","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/devenv-report-ext-example, 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/devenv-report-ext-example","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":"Reports are used to print or display information from a database.","date":"2021-04-01","meta":{"topic":"how-to"},"outline":[{"level":1,"title":"Report Extension Example","slug":"report-extension-example","at":0,"chars":6407},{"level":2,"title":"The base table - BaseFoodTable","slug":"the-base-table---basefoodtable","at":425,"chars":1191},{"level":3,"title":"Defining an enum - FoodColor","slug":"defining-an-enum---foodcolor","at":1268,"chars":348},{"level":2,"title":"The base report - FoodReport","slug":"the-base-report---foodreport","at":1616,"chars":1040},{"level":2,"title":"The table extension - GMOFood","slug":"the-table-extension---gmofood","at":2656,"chars":731},{"level":2,"title":"The report extension - FoodExtension","slug":"the-report-extension---foodextension","at":3387,"chars":1537},{"level":2,"title":"Related information","slug":"related-information","at":4924,"chars":1483}],"text":"# Report Extension Example\nThe following article illustrates how an existing table and report is extended by using extension objects. The code snippets shown in this example don't provide a full end-to-end scenario that can be deployed; they're intended to illustrate the way to extend existing functionality by using the Table Extension Object<devenv-table-ext-object> and Report Extension Object<devenv-report-ext-object>.\n## The base table - BaseFoodTable\nThe report extension will be based on the following base table, which holds information about food and specific details that applies to that. The Color field in this table is an enum, which is defined with the FoodColor enum next.\n```al\ntable 50100 BaseFoodTable\n{\n    DataClassification = ToBeClassified;\n    DataPerCompany = false;\n\n    fields\n    {\n        field(1; Name; Text[256]) { }\n        field(2; Color; Enum FoodColor) { }\n        field(3; Flavour; Text[256]) { }\n        field(4; \"Vegan Friendly\"; Boolean) { }\n        field(5; \"Vegetarian Friendly\"; Boolean) { }\n        field(7; Price; Decimal)\n        {\n            DecimalPlaces = 2;\n        }\n\n        field(8; Restaurant; Integer) { }\n    }\n\n    keys\n    {\n        key(PK; Name)\n        {\n            Clustered = true;\n        }\n    }\n}\n```\n### Defining an enum - FoodColor\nThe FoodColor enum enables selecting a descriptive color of an item in the BaseFoodTable.\n```al\nenum 50100 FoodColor\n{\n    Extensible = true;\n\n    value(0; White) { }\n    value(1; Red) { }\n    value(2; Black) { }\n    value(3; Brown) { }\n    value(4; Orange) { }\n    value(5; Green) { }\n    value(6; Blue) { }\n}\n```\n## The base report - FoodReport\nThe following FoodReport object defines a report based on BaseFoodTable as a data source. There's a DataItemLink to a second table that displays restaurant information. The report is defined with an RDL layout. See Creating an RDL Layout Report<devenv-howto-rdl-report-layout>.\n```al\nreport 50100 FoodReport\n{\n    UsageCategory = Administration;\n    ApplicationArea = All;\n    DefaultLayout = RDLC;\n    RDLCLayout = 'FoodReport.rdl';\n    AllowScheduling = true;\n\n    dataset\n    {\n        dataitem(FoodTable; BaseFoodTable)\n        {\n            column(Name; Name) { }\n            column(Color; Color) { }\n            column(Flavour; Flavour) { }\n            column(Vegan_Friendly; \"Vegan Friendly\") { }\n            column(Vegetarian_Friendly; \"Vegetarian Friendly\") { }\n            column(Price; Price) { }\n            dataitem(Restaurant; Restaurant)\n            {\n                DataItemLink = ID = field(Restaurant);\n                column(RestaurantName; Name) { }\n            }\n\n        }\n    }\n}\n```\n## The table extension - GMOFood\nIn the next code snippet, the table extension GMOFood is defined. This table extension extends the BaseFoodTable with extra fields to register more details about food. GMOFood adds a relation to the Producer table through the ProducerID key.\n```al\ntableextension 50200 GMOFood extends BaseFoodTable\n{\n    fields\n    {\n        field(100; \"GMO Free\"; Boolean) { }\n        field(101; Organic; Boolean) { }\n\n        field(103; Calories; Decimal)\n        {\n            DecimalPlaces = 3;\n        }\n        field(102; ProducerID; Integer) { }\n    }\n}\n\ntable 50202 Producer\n{\n    DataPerCompany = false;\n    fields\n    {\n        field(1; ID; Integer) { }\n        field(2; Name; Text[256]) { }\n    }\n}\n```\n## The report extension - FoodExtension\nAs we've seen in the previous sections, the base table BaseFoodTable was extended with the GMOFood extension. To reflect that change, it makes sense to extend the FoodReport to enable displaying the extra set of fields that were added; both to the existing FoodTable and to the new table Producer. To do that, we need to use a report extension object. See Report Extension Object<devenv-report-ext-object>. In the dataset element, three new columns are added to the FoodTable dataitem, and a new dataitem element is introduced that adds columns corresponding to the reports source table.\n```al\nreportextension 50200 FoodExtension extends FoodReport\n{\n    RDLCLayout = 'ExtendedFoodReport.rdl';\n\n    dataset\n    {\n        add(FoodTable)\n        {\n            column(GMO_Free; \"GMO Free\") { }\n            column(Organic; Organic) { }\n            column(Calories; Calories) { }\n        }\n\n        addfirst(Restaurant)\n        {\n            dataitem(Producer; Producer)\n            {\n                DataItemLink = ID = field(ProducerID);\n                DataItemLinkReference = FoodTable;\n                column(ProducerName; Name) { }\n            }\n        }\n    }\n}\n```\nThe example code above illustrates how additive changes to tables that are used on reports can use report extension objects to reflect these changes.\nNote that `addfirst(Restaurant)` will add the new Producer dataitem as the first child dataitem under the existing Restaurant dataitem. It won't add another Restaurant dataitem.\n## Related information\nReports Overview<devenv-reports>\ndevenv-report-object\nReport Extension Object<devenv-report-ext-object>\nUsing request pages with reports<devenv-request-pages-for-reports>\nReport extension triggers\nOnPostReport (Report Extension) Trigger<triggers-auto/reportextension/devenv-onpostreport-reportextension-trigger>\nOnPreReport (Report Extension) Trigger<triggers-auto/reportextension/devenv-onprereport-reportextension-trigger>\nOnAfterAfterGetRecord (Report Extension Data Set Modify) Trigger<triggers-auto/reportextensiondatasetmodify/devenv-onafteraftergetrecord-reportextensiondatasetmodify-trigger>\nOnAfterPostDataItem (Report Extension Data Set Modify) Trigger<triggers-auto/reportextensiondatasetmodify/devenv-onafterpostdataitem-reportextensiondatasetmodify-trigger>\nOnAfterPreDataItem (Report Extension Data Set Modify) Trigger<triggers-auto/reportextensiondatasetmodify/devenv-onafterpredataitem-reportextensiondatasetmodify-trigger>\nOnBeforeAfterGetRecord (Report Extension Data Set Modify) Trigger<triggers-auto/reportextensiondatasetmodify/devenv-onbeforeaftergetrecord-reportextensiondatasetmodify-trigger>\nOnBeforePostDataItem (Report Extension Data Set Modify) Trigger<triggers-auto/reportextensiondatasetmodify/devenv-onbeforepostdataitem-reportextensiondatasetmodify-trigger>\nOnBeforePreDataItem (Report Extension Data Set Modify) Trigger<triggers-auto/reportextensiondatasetmodify/devenv-onbeforepredataitem-reportextensiondatasetmodify-trigger>"}