Exercise - Create the Customer List page extension object

Completed

Scenario

On the Customer List page, you want to add an action. This action should open the list of reward levels.

In Business Central, actions are displayed at the top of each page and are referred to as the action bar. Each page has a different set of actions, depending on the page type, and the processes that the page supports. To create the appropriate set of actions for a page, you should have a good understanding of your customer's business processes.

The following page extension object extends the Customer List page object by adding the Reward Levels action control to the Customer group on the page.

Create the Customer List page extension object

To create the Customer List 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 CustomerList.PageExt.al.

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

    pageextension 50101 CustomerList extends "Customer List"
    {
        actions
        {
            addfirst("&Customer")
            {
                action("Reward Levels")
                {
                    ApplicationArea = All;
                    Image = CustomerRating;
                    Promoted = true;
                    PromotedCategory = Process;
                    PromotedIsBig = true;
                    ToolTip = 'Open the list of reward levels.';
    
                    trigger OnAction();
                    var
                        CustomerRewardsExtMgt: Codeunit "Customer Rewards Ext Mgt";
                    begin
                        if CustomerRewardsExtMgt.IsCustomerRewardsActivated then
                            CustomerRewardsExtMgt.OpenRewardsLevelPage
                        else
                            CustomerRewardsExtMgt.OpenCustomerRewardsWizard;
                    end;
                }
            }
        }
    } 
    

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.