{"title":"Extending Customer, Vendor, and Item Templates","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/devenv-extending-templates/","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-extending-templates, 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-extending-templates","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":"How you extend templates in Dynamics 365 Business Central.","date":"2021-10-14","meta":{"topic":"concept-article"},"outline":[{"level":1,"title":"Extending Customer, Vendor, and Item Templates","slug":"extending-customer-vendor-and-item-templates","at":0,"chars":8315},{"level":2,"title":"Example: Extend an existing customer template by adding a field","slug":"example-extend-an-existing-customer-template-by-adding-a-field","at":202,"chars":390},{"level":2,"title":"Example: Use configuration templates","slug":"example-use-configuration-templates","at":592,"chars":679},{"level":2,"title":"Example: Verify the fields you added to extend existing primary template table and template card","slug":"example-verify-the-fields-you-added-to-extend-existing-primary-template-table-and-template-card","at":1271,"chars":1437},{"level":2,"title":"Example: Create a new template for the primary table","slug":"example-create-a-new-template-for-the-primary-table","at":2708,"chars":5550},{"level":2,"title":"Related information","slug":"related-information","at":8258,"chars":57}],"text":"# Extending Customer, Vendor, and Item Templates\nYou can extend customer, vendor, and item templates, or create your own template and use it for primary tables. The following sections provide examples.\n## Example: Extend an existing customer template by adding a field\nYou can add a field to a customer template, and then include the field when someone uses the template to create a new customer. You just need to add field with the same number, type, and length, to the Customer and Customer Templ. tables. Dynamics 365 Business Central will transfer value from the template to new records.\n## Example: Use configuration templates\nThis example shows how use configuration templates instead of creating new templates.\n```al\ncodeunit 50102 ConfigTemplateExtMgt\n{\n    trigger OnRun()\n    begin\n    end;\n\n    [EventSubscriber(ObjectType::Codeunit, Codeunit::\"Customer Templ. Mgt.\", 'OnBeforeCreateCustomerFromTemplate', '', false, false)]\n    local procedure OnBeforeCreateCustomerFromTemplateHandler(var Customer: Record Customer; var Result: Boolean; var IsHandled: Boolean)\n    var\n        MiniCustomerTemplate: Record \"Mini Customer Template\";\n    begin\n        IsHandled := true;\n        Result := MiniCustomerTemplate.NewCustomerFromTemplate(Customer);\n    end;\n}\n```\n## Example: Verify the fields you added to extend existing primary template table and template card\nThis example shows how to verify the fields you added to existing templates with a data and template card. You can run this procedure in tests, for example, to ensure that the fields you added on the Customer Card page also exist on the Customer Template Card page.\n```al\n    procedure CustomerTemplCardControls()\n    var\n        CustomerCardPageControlField: Record \"Page Control Field\";\n        CustomerTemplCardPageControlField: Record \"Page Control Field\";\n        CustomerTemplField: Record Field;\n    begin\n        CustomerTemplCardPageControlField.SetRange(PageNo, Page::\"Customer Templ. Card\");\n\n        CustomerCardPageControlField.SetRange(PageNo, Page::\"Customer Card\");\n        CustomerCardPageControlField.SetFilter(FieldNo, '<>0');\n        if CustomerCardPageControlField.FindSet() then\n            repeat\n                if CustomerTemplField.Get(Database::\"Customer Templ.\", CustomerCardPageControlField.FieldNo) then begin\n                    CustomerTemplCardPageControlField.SetRange(FieldNo, CustomerCardPageControlField.FieldNo);\n                    if CustomerTemplCardPageControlField.IsEmpty then\n                        Error('%1 should exist on the customer template card.', CustomerCardPageControlField.ControlName);\n                end;\n            until CustomerCardPageControlField.Next() = 0;\n    end;\n```\n## Example: Create a new template for the primary table\nThis example shows how to create a template for the Resource table, and then use the template to create a new resource. Let's extend the Resource table by adding a new field named Extension Field.\n```al\ntableextension 50101 ResourceExt extends Resource\n{\n    fields\n    {\n        field(50101; \"Extension Field\"; Text[50])\n        {\n            Caption = 'Extension Field';\n        }\n    }\n}\n\npageextension 50102 ResourceCardExt extends \"Resource Card\"\n{\n    layout\n    {\n        addlast(General)\n        {\n            field(\"Extension Field\"; \"Extension Field\")\n            {\n                ApplicationArea = All;\n            }\n        }\n    }\n}\n```\nHere's a new template table for resources.\n```al\ntable 50103 \"Resource Template\"\n{\n    fields\n    {\n        field(1; Code; Code[20])\n        {\n            Caption = 'Code';\n            NotBlank = true;\n        }\n        field(14; \"Resource Group No.\"; Code[20])\n        {\n            Caption = 'Resource Group No.';\n            TableRelation = \"Resource Group\";\n        }\n        field(50100; \"Template Description\"; Text[50])\n        {\n            Caption = 'Template Description';\n        }\n        field(50101; \"Extension Field\"; Text[50])\n        {\n            Caption = 'Extension Field';\n        }\n    }\n\n    keys\n    {\n        key(Key1; Code)\n        {\n            Clustered = true;\n        }\n    }\n}\n```\nThe following card and list pages for the new template allow you to edit the template, or select it when you create a new resource.\n```al\npage 50104 \"Resource Template Card\"\n{\n    PageType = Card;\n    SourceTable = \"Resource Template\";\n\n    layout\n    {\n        area(Content)\n        {\n            group(General)\n            {\n                Caption = 'General';\n\n                field(Code; Code)\n                {\n                    ApplicationArea = All;\n                }\n                field(\"Template Description\"; \"Template Description\")\n                {\n                    ApplicationArea = All;\n                }\n            }\n            group(Details)\n            {\n                Caption = 'Details';\n\n                field(\"Resource Group No.\"; \"Resource Group No.\")\n                {\n                    ApplicationArea = All;\n                }\n                field(\"Extension Field\"; \"Extension Field\")\n                {\n                    ApplicationArea = All;\n                }\n            }\n        }\n    }\n}\n\npage 50105 \"Resource Template List\"\n{\n    Caption = 'Resource Templates';\n    PageType = List;\n    ApplicationArea = All;\n    UsageCategory = Lists;\n    SourceTable = \"Resource Template\";\n    CardPageId = \"Resource Template Card\";\n\n    layout\n    {\n        area(Content)\n        {\n            repeater(Templates)\n            {\n                field(Code; Code)\n                {\n                    ApplicationArea = All;\n                }\n                field(\"Template Description\"; \"Template Description\")\n                {\n                    ApplicationArea = All;\n                }\n            }\n        }\n    }\n}\n```\nThe following management codeunit runs the template list page for selecting templates when you create a new resource. It also transfers data from the Extension Field and Resource Group No. fields from the template to the Resource record.\n```al\ncodeunit 50101 TemplateExtMgt\n{\n    SingleInstance = true;\n\n    trigger OnRun()\n    begin\n    end;\n\n    var\n        ResourceNewMode: Boolean;\n\n    local procedure CreateResourceFromTemplate(var Resource: Record Resource)\n    var\n        SrcResource: Record Resource;\n        ResourceTemplate: Record \"Resource Template\";\n    begin\n        if not ResourceNewMode then\n            exit;\n\n        ResourceNewMode := false;\n\n        if not SelectResourceTemplate(ResourceTemplate) then\n            exit;\n\n        SrcResource.Init();\n        SrcResource.Insert(true);\n\n        SrcResource.\"Resource Group No.\" := ResourceTemplate.\"Resource Group No.\";\n        SrcResource.\"Extension Field\" := ResourceTemplate.\"Extension Field\";\n        SrcResource.Modify();\n\n        Resource.Copy(SrcResource);\n    end;\n\n    local procedure SelectResourceTemplate(var ResourceTemplate: Record \"Resource Template\"): Boolean\n    var\n        ResourceTemplateList: Page \"Resource Template List\";\n    begin\n        if ResourceTemplate.Count = 1 then begin\n            ResourceTemplate.FindFirst();\n            exit(true);\n        end;\n\n        if (ResourceTemplate.Count > 1) and GuiAllowed then begin\n            ResourceTemplateList.SetTableView(ResourceTemplate);\n            ResourceTemplateList.LookupMode(true);\n            if ResourceTemplateList.RunModal() = Action::LookupOK then begin\n                ResourceTemplateList.GetRecord(ResourceTemplate);\n                exit(true);\n            end;\n        end;\n\n        exit(false);\n    end;\n\n    [EventSubscriber(ObjectType::Page, Page::\"Resource Card\", 'OnNewRecordEvent', '', false, false)]\n    local procedure OnNewRecordEventHandler()\n    begin\n        ResourceNewMode := true;\n    end;\n\n    [EventSubscriber(ObjectType::Page, Page::\"Resource Card\", 'OnAfterGetCurrRecordEvent', '', false, false)]\n    local procedure OnAfterGetCurrRecordEventHandler(var Rec: Record Resource)\n    begin\n        CreateResourceFromTemplate(Rec);\n    end;\n\n    [EventSubscriber(ObjectType::Page, Page::\"Resource Card\", 'OnBeforeOnAfterGetCurrRecord', '', false, false)]\n    local procedure OnBeforeOnAfterGetCurrRecordHandler(sender: Page \"Resource Card\")\n    begin\n        sender.Update();\n    end;\n}\n```\n## Related information\ndevenv-extending-application-areas"}