web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Reportextension. Global variable is cleared in Preview Mode

(0) ShareShare
ReportReport
Posted on by 3,029

So I have extended the Standard - Sales Order Confirmation report:

reportextension 50003 "Custom Sales-Order Con" extends "Standard Sales - Order Conf."
{
    dataset
    {
        addfirst(Header)
        {
            dataitem("Caja"; "Caja")
            {
               //JUST A RELATION WITH A CUSTOM TABLE
                DataItemLink = "Document No." = field("No.");
                DataItemLinkReference = Header;
                DataItemTableView = where(Anticipo = const(true));
                column(anticipo_Fecha; "Fecha pago") { }               

                //WITH THIS FUNCTION I FILTER MY DATAITEM USING THE GLOBAL VARIABLE 
                trigger OnPreDataItem()
                begin
                    if anticipoDate = 0D then
                        CurrReport.Skip()
                    else
                        SetRange("Caja"."Fecha pago", anticipoDate);
                end;
            }
        }

    }
   //A NEW GLOBAL VARIABLE
    var
        anticipoDate: Date;

   
    //A PROCEDURE TO SET THE NEW GLOBAL VARIABLE
    procedure setAnticipoDate(parmDate: Date)
    begin
        anticipoDate := parmDate;
    end;
}
Now from a page action, i call this report:
            action(print)
            {
                ApplicationArea = All;
                Caption = 'Imprimir Prepago';
                Image = PrintAttachment;


                trigger OnAction()
                var
                    reportPrepago: Report "Standard Sales - Order Conf."
                    recFilter: Record "Sales Header";
                    datefilter: Date;
                    RLS: Record "Report Layout Selection";
                begin                    
                    recFilter.SetRange("Document Type", "Document Type"::Order);
                    recFilter.SetRange("No.", Rec."Document No.");                    
                    reportPrepago.SetTableView(recFilter);
                    RLS.SetTempLayoutSelected('1305-000003'); //This is just to force a custom design for the report
                    reportPrepago.setAnticipoDate(Rec."Fecha pago"); //I CALL MY FUNCTION TO SET THE GLOBAL VARIABLE
                    reportPrepago.RunModal();
                    RLS.SetTempLayoutSelected('');
                end;
            }
Once the request page opens, if I choose to PRINT the report, everything works as expected, the filter is correctly applied to my custom DataItem. However, the problem is in the page preview, the Global Variable is cleared, and my dataitem is not even filtered.
Maybe it has something to do with this blog post by Stefano Demiliani , but I have no idea how can I avoid this behaviour:  
   
 
Using OnPremise BC 21.1.48363
I have the same question (0)
  • Suggested answer
    Andy Sather Profile Picture
    Microsoft Employee on at

    Hello,

    If you don't get further responses to this issue, you may want to raise a support request to Microsoft support via your CSP / Partner.

  • Ghetz Profile Picture
    3,029 on at

    Would be nice to have a confirmation that this happens in other installations and not only mine before raising a support request.

  • Community member Profile Picture
    on at
    We have the same issue.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 524 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 399 Super User 2026 Season 2

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 354 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans