Exercise - Create the Customer Card page extension object

Completed

Scenario

The following page extension object extends the Customer Card page object. In this exercise, you'll add the RewardLevel and RewardPoints field controls after the Name field control on the page. The fields are added in the layout section.

Create the Customer Card page extension object

To create the Customer Card page extension object, follow these steps:

  1. Create a new .al file.

    1. To create a new page in your extension, first create a new file. Select the New File button in the side bar of Visual Studio Code.

    2. Make sure that the filename ends with .al. In this example, you might want to use the name CustomerCard.PageExt.al.

  2. Add the code to the page. You can copy the following code and paste it in the CustomerCard.PageExt.al file.

     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; 
     } 
    

Note

The codeunit Customer Rewards Ext Mgt does not exist yet, so the compiler will show an error. To avoid that, you can comment out that part of the code.