Set number of copies in a FORNAV report

FORNAV has a great tool for setting the number of copies in a report. Instead of adding a CopyLoop data item, you can simply set the number of copies with a function call.

There are a few steps to add this code. First, you need to create a global variable to hold the number of copies:

    trigger OnPreReport()
    begin
        ReportForNav.SetCopies('Header', NoOfCopies);
        ReportForNav.LoadWatermarkFromSetup(ForNav_WatermarkType::Document);
    end;

    var
        NoOfCopies: Integer;

Next, you set the No. of Copies on the report request page:

requestpage
    {

        SaveValues = true;

        layout
        {
            area(content)
            {
                group(Options)
                {
                    Caption = 'Options';
                    field(NoOfCopies; NoOfCopies)
                    {
                        ApplicationArea = All;
                        Caption = 'No. of Copies';
                    }
                }
            }
        }
    }

Finally, you set the number of copies in the OnPreReport trigger for the Universal Code version of FORNAV reports:

    trigger OnPreReport()
    begin
        ReportForNav.SetCopies('Header', NoOfCopies);
    end;

And the version for the DLL based reports:

    trigger OnPreReport()
    begin
        ReportForNav.GetDataItem('Header').Copies := NoOfCopies;
        ReportsForNavPre;
    end;

Set the No Of Copies when you run a report

In some cases, you might need to set the No Of Copies when you run a report from AL Code. You can do this by setting the NoOfCopies request page value in the report parameters.

    local procedure RunReportWithNumberOfCopies()
    var
        Item: Record Item;
        ItemLabel: Report "ForNAV Item - Label";
        RecRef: RecordRef;
        ReqPageParams: Text;
        NoOfCopies: Integer;
    begin
        NoOfCopies := 2;
        Item := Rec;
        Item.SetRecFilter();
        // ReqPageParams := Report.RunRequestPage(Report::"ForNAV Item - Label");
        ReqPageParams := StrSubstNo('<?xml version="1.0" standalone="yes"?><ReportParameters name="ForNAV Item - Label" id="6188685"><Options><Field name="NoOfCopies">%1</Field></Options></ReportParameters>', NoOfCopies);
        RecRef.GetTable(Item);
        Report.Execute(Report::"ForNAV Item - Label", ReqPageParams, RecRef);
    end;

You can find the full code on GitHub: https://github.com/fornav/ForNav.Training/tree/master/FORNAV.SetNoOfCopies