Create the customer card page extension object

Completed

A page extension object can be used to add new functionality to pages that are part of the Business Central service.

The following page extension object extends the Customer Card page object by adding the RewardLevel and RewardPoints field controls after the Name field control on the page. The fields are added in the layout section.

```al-language
pageextension 50100 "Customer Card" extends "Customer Card" 
{ 
    layout 
    { 
        addafter(Name) 
        { 
            field(RewardLevel; RewardLevel) 
            { 
                ApplicationArea = All; 
                Caption = 'Reward Level'; 
                Description = 'Reward level of the customer.'; 
                ToolTip = 'Specifies the level of reward that the customer has at this point.';
                Editable = false; 
            } 

            field(RewardPoints; Rec.RewardPoints) 
            { 
                ApplicationArea = All; 
                Caption = 'Reward Points'; 
                Description = 'Reward points accrued by customer'; 
                ToolTip = 'Specifies the total number of points that the customer has at this point.';
                Editable = false;
            }
        }
    }

    trigger OnAfterGetRecord(); 
    var 
        CustomerRewardsMgtExt: Codeunit "Customer Rewards Ext. Mgt."; 
    begin 
        // Get the reward level associated with reward points 
        RewardLevel := CustomerRewardsMgtExt.GetRewardLevel(Rec.RewardPoints); 
    end; 

    var 
        RewardLevel: Text; 
} 

```

Entering the tpageext shortcut will create the basic layout for a page extension object when you're using the AL Language extension in Visual Studio Code.

Whether you're creating a new page or extending an existing page, you'll add a new .al file to your project and describe the page object in code. The basic difference is that for a new page, you need to define the entire page, whereas when you're modifying an existing page, you only add the extra functionality or modify the existing page.

You can use keywords in the layout section of a page extension to place and move fields and groups on the page. Similarly, in the actions section, you can use these keywords to place actions in the ribbon.

In this example, you'll use the keyword addafter(Name) to indicate that you want to add the fields after the Name field, which is currently already present on the Customer Card page.

You can use the Ctrl+Space keyboard shortcut to trigger IntelliSense and get assistance on code completion, parameter info, quick info, and member lists. This feature can be helpful when you're creating page extension objects.

Note

Later in this module there is an exercise where you can create this object, following step by step instructions.

Because the codeunit Customer Rewards Ext Mgt doesn't exist yet, the compiler will show an error on this line. To remove the error, temporarily, comment out that section of the code.