How to Print Multiple Copies in Report in AL of Microsoft Dynamics 365 Business Central (MSDYN365BC)?

Hi ALL,

This was busy week with an upgrade project which went live this weekend from Dynamics NAV 2015 to Business Central 13. Lets start with todays topic of printing multiple copies in Report of AL for Dynamics 365 Business Central. I have got request from many of our fellow developers to write something on this topic.

Lets get started.

You can refer my previous blog Creating an RDL Layout Report in Microsoft Dynamics 365 Business Central (MSDYN365BC).

There are two parts in report

  1. AL Code
  2. RDL Layout (Similar to NAV).

AL Code

I have pasted the AL code for the Item List report.

 report 50129 ItemListReport
{
    UsageCategory = ReportsAndAnalysis;
    ApplicationArea = All;
    CaptionML = ENU = 'AL Item List ';
    DefaultLayout = RDLC;
    RDLCLayout = './ItemListReport.rdl';
    dataset
    {
        dataitem(Item; Item)
        {
            dataitem(CopyLoop; "Integer")
            {
                DataItemTableView = SORTING(Number);
                dataitem(PageLoop; "Integer")
                {
                    DataItemTableView = SORTING(Number) WHERE(Number = CONST(1));
                    column(ItemNo; Item."No."){}
                    column(ItemName; Item.Description){ }
                    column(ItemUOM; Item."Base Unit of Measure"){ }
                    Column(ItemCost; Item."Unit Cost"){ }
                    column(ItemPrice; Item."Unit Price"){ }
                    column(ShowUnitCost; ShowUnitCost){ }
                    column(Outputno; OutputNo){}
                    column(CopyText; CopyText){}
                }
                trigger OnAfterGetRecord();
                begin
                    if Number > 1 then begin
                        CopyText := FormatDocument.GetCOPYText;
                        OutputNo += 1;
                    end;
                end;
                trigger OnPreDataItem();
                begin
                    NoOfLoops := ABS(NoOfCopies) + 1;
                    CopyText := '';
                    SETRANGE(Number, 1, NoOfLoops);
                    OutputNo := 1;
                end;
            }
        }
    }
    requestpage
    {
        layout
        {
            area(Content)
            {
                group(GroupName)
                {
                    field("Show Unit Cost"; ShowUnitCost)
                    {}
                    field(NoOfCopies; NoOfCopies)
                    {
                        ApplicationArea = Advanced;
                    }
                }
            }
        }
        actions
        {
            area(processing)
            {
                action(ActionName)
                {
                    ApplicationArea = All;
                }
            }
        }
    }
    var
        ShowUnitCost: Boolean;
        NoOfCopies: Integer;
        NoOfLoops: Integer;
        CopyText: Text[30];
        OutputNo: Integer;
        FormatDocument: Codeunit "Format Document";
} 

As you can see i have added CopyLoop and PageLoop as a dataitem after the Item Dataitem similar to that in C/AL, Logic remains the same (Syntax changes).

I have added the code which is bold in above AL Code.

RDL Layout (Similar to NAV).

We have created RDL Layout in prev blog and we will be modfying the same for printing multiple copies in AL.

Add list to Layout MSDYN365BC

Let insert a List by Right click on the empty space as shown above. we will add group on OutputNo and Pagebreak for the same as shown in below screenshot

Add group and Page Break to layout MSDYN365BC

Now place the Table inside the List

Add List and Report MSDYN365BC

Thats it your report is ready.

SAVE and CLOSE the SQL Server Report Builder.

Back in Visual Studio Code, press Ctrl+F5 to compile and run the report in Dynamics 365 Business Central.

Open Mordern Client search for AL ITEM LIST report and select Report, specify filter if required and run Report.

Add NoOfCopies as 1 and adding filter on Item No. to reduce the Records and Print.

Request page with NoOfCopies MSDYN365BC

Below is the output of the report having 2 copies.

NoOfCopies in AL MSDYN365BC

So we have created a RDL Layout Report with Multiple Copies in AL for Microsoft Dynamics 365 Business Central.

To get new updates and learn about Microsoft Dynamics 365 Business Central Microsoft Learn

Thanks for reading.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s