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

Notifications

Announcements

No record found.

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,013

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
    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,013 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,229

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,867 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,153 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans