Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

Reportextension. Global variable is cleared in Preview Mode

(0) ShareShare
ReportReport
Posted on by 2,983

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
  • Reportextension. Global variable is cleared in Preview Mode
    We have the same issue.
  • Ghetz Profile Picture
    Ghetz 2,983 on at
    RE: Reportextension. Global variable is cleared in Preview Mode

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

  • Suggested answer
    Andy Sather Profile Picture
    Andy Sather on at
    RE: Reportextension. Global variable is cleared in Preview Mode

    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.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans