Exercise - Discover the intrinsic data types

Completed

You're a developer for CRONUS International Ltd. and have learned how to use variables in AL. Now, you want to practice declaring and using different types of variables. You also want to learn how the variable values can be shown on screen and what the initial (default) values are for various data types.

Tasks

  • Create a new AL extension.

  • Create a new card page.

  • Create global variables.

  • Display the values of the variables in a message box.

Steps

  1. Start Visual Studio Code.

  2. Select View > Extensions (Ctrl+Shift+X).

  3. Enter AL Language in the Search Extensions in the Marketplace search box.

  4. Select the green Install button.

  5. Create a new AL extension project. Select View > Command Palette... (Ctrl+Shift+P).

  6. Enter AL: Go! in the search box and select the command from the list.

  7. Accept the suggested path (or enter another path).

  8. Select the 10.0 Business Central 2022 release wave 2 target platform.

  9. Select Microsoft cloud sandbox as the development endpoint.

  10. Download the application symbols. Select View > Command Palette... (Ctrl+Shift+P).

    • Enter AL: Download symbols in the search box and select the command from the list.

    • If requested, provide your organizational credentials (Microsoft 365 account/Microsoft Entra ID account).

  11. Open the app.json file and change the name setting to DataTypes. Change the publisher setting to Cronus International Ltd.

  12. Remove the HelloWorld.al file.

  13. Select File > New File and immediately save this file by selecting File > Save. Name the file DataTypesCard.Page.al.

  14. Create a new page in this file by using code snippets. Enter tpage and press the second option in the dropdown.

  15. Change the ID to 50110 and the name to DataTypesCard.

  16. Verify the PageType property is set to Card.

  17. Set the UsageCategory property to Documents.

  18. In the layout section, remove the field(Name; NameSource).

  19. In the actions, remove the action(ActionName).

  20. Set the PageType property to Card and set the UsageCategory property to Documents.

  21. Remove the SourceTable property and set the Caption property to Date Types Card.

  22. Create the following global variables and remove the default myInt variable.

    • LoopNo Integer

    • YesOrNo Boolean

    • Amount Decimal

    • "When Was It" Date

    • "What Time" Time

    • Description Text[30]

    • "Code Number" Code[10]

    • Ch Char

    • Color Option (values: Red, Orange, Yellow, Green, Blue, Violet)

  23. Under the actions, create a new trigger with the name OnOpenPage.

  24. Enter the following code within begin and end of the OnOpenPage trigger.

     Message('The value of %1 is %2','YesOrNo',YesOrNo);
     Message('The value of %1 is %2','Amount',Amount);
     Message('The value of %1 is %2','When Was It',"When Was It");
     Message('The value of %1 is %2','What Time',"What Time");
     Message('The value of %1 is %2','Description',Description);
     Message('The value of %1 is %2','Code Number',"Code Number");
     Message('The value of %1 is %2','Ch',Ch);
     Message('The value of %1 is %2','Color',Color);
    
  25. The DataTypesCard page code should now resemble this:

    page 50110 DataTypesCard
    {
        PageType = Card;
        ApplicationArea = All;
        UsageCategory = Documents;
        Caption = 'Data Types Card';
    
        layout
        {
            area(Content)
            {
                group(GroupName)
                {
    
                }
            }
        }
    
        actions
        {
            area(Processing)
            {
    
            }
        }
        trigger OnOpenPage()
        begin
            Message('The value of %1 is %2', 'YesOrNo', YesOrNo);
            Message('The value of %1 is %2', 'Amount', Amount);
            Message('The value of %1 is %2', 'When Was It', "When Was It");
            Message('The value of %1 is %2', 'What Time', "What Time");
            Message('The value of %1 is %2', 'Description', Description);
            Message('The value of %1 is %2', 'Code Number', "Code Number");
            Message('The value of %1 is %2', 'Ch', Ch);
            Message('The value of %1 is %2', 'Color', Color);
    
        end;
    
        var
            LoopNo: Integer;
            YesOrNo: Boolean;
            Amount: Decimal;
            "When Was It": Date;
            "What Time": Time;
            Description: Text[30];
            "Code Number": Code[10];
            Ch: Char;
            Color: Option Red,Orange,Yellow,Green,Blue,Violet;
    }
    
  26. Open the launch.json file in the .vscode folder. Set the startupObjectId setting to 50110 and the startupObjectType setting to Page.

  27. Publish your extension to the sandbox. Select View > Command Palette... (Ctrl+Shift+P).

  28. Enter AL: Publish in the search box (or press the F5 key) and then select the command from the list.

  29. Verify that the Dynamics 365 Business Central application launches and that the Date Types Card page appears. You should see message boxes with the values of each of the variables.

  30. You should see message boxes with the values of each of the variables.

  31. Because you did not assign any values yet to the variables, the default values are displayed.