Wednesday, November 14, 2018

Reports in Extension using AL and Report Builder


How to create and design report in Business Central Extension using AL and Report Builder


Below are simple steps to create and design simple report in Business Central through AL & Report Builder. Even in C/AL we were designing reports layout in report builder. Same process has been provided with AL as well, where we will define data items & logic in AL code, later we will design layout in Report Builder. Finally, we will publish / build our report extension.


I will try to demonstrate below sample with AL & Report Builder together:





Step 1: Copy and Paste (Write) below code in AL (Visual Studio Code):


report 50101 "My Customer List"
{
    CaptionML = ENU = 'My Customer List';
    RDLCLayout = 'My Customer List.rdl';
    dataset
    {
        dataitem(Customer; Customer)
        {
            RequestFilterFields = "No.", "Search Name", "Customer Posting Group";
            column(CompnayName; COMPANYNAME)
            {
            }
            column(Customer_TABLECAPTION_CustFilter; TABLECAPTION + ': ' + CustFilter)
            {
            }
            column(CustomerNo; "No.")
            {
            }
            column(PostingGrou; "Customer Posting Group")
            {
            }
            column(Balance__LCY_; "Balance (LCY)")
            {
            }

            trigger OnAfterGetRecord();
            begin
                CalcFields("Balance (LCY)");
            end;

        }

    }
   
    requestpage
    {
        SaveValues = true;

        layout
        {
        }

        actions
        {
        }

    }

    labels
    {
    }

    trigger OnPreReport();
    var
        CaptionManagement: Codeunit 42;
    begin
        CustFilter := CaptionManagement.GetRecordFiltersWithCaptions(Customer);
    end;

    var
        CustFilter: Text;
}



Step 2: Save (Ctrl + S) and Build your extension (Ctrl + Shift + B) to generate “My Customer List.rdl”






Step 3: Open Report Builder 2016 and open “My Customer List.rdl” file from AL Project directory (for my case, I have saved my project in C:\Users\UserID\Documents\AL\ALProject2).


Find the report builder from app list:





Open “My Customer List.rdl” from project directory:




Design layout with published data sources & datasets:




Save and close the Report Builder.



Step 4: Attach report to page extension (initial Hello World J extension):


pageextension 50100 CustomerListExt extends "Customer List"
{
    actions
    {
        addlast(Navigation)
        {
            action("My Customer List")
            {
                ApplicationArea = All;
                RunObject = report "My Customer List";
                Image = "Report";
            }
        }
    }

    trigger OnOpenPage();
    begin
        Message('[Business Central] App published: Hello world');
    end;
}




Step 5: Build your extension & deploy (Shift + F5 / F5) to Business central. Check the page and run you report:






J Here you have done 1st report walk-through. Enjoy and keep extending Business Central using AL (Visual Studio Code)…

No comments:

Post a Comment