microsoft / AL

Home of the Dynamics 365 Business Central AL Language extension for Visual Studio Code. Used to track issues regarding the latest version of the AL compiler and developer tools available in the Visual Studio Code Marketplace or as part of the AL Developer Preview builds for Dynamics 365 Business Central.
MIT License
744 stars 244 forks source link

OnOpenPage in ReportExtension RequestPage runs too often #7112

Closed JulianTillmann closed 2 years ago

JulianTillmann commented 2 years ago

1. Describe the bug When using a ReportExtension with the trigger OnOpenPage() for the request page it seems to be running when the requestpage is opened, as it should be, but also when the report is run.

This is a problem when trying to initialize variables for the request page. Any value changed by the user in the request page it re-set when the report starts.

2. To Reproduce Create a report extension which is initializing a variable in the OnOpenPage()-trigger. Add Messages to confirm the value of the variable and where it's run, for example:

reportextension 72799 MyReportExtension extends "Customer - Top 10 List"
{

    dataset
    {
        modify(Integer)
        {
            trigger OnAfterAfterGetRecord()
            begin
                ERROR('Integer-DataItem: %1', SomeVariable);
            end;

        }
    }

    requestpage
    {
        layout
        {
            addfirst(Options)
            {
                field(SomeField; SomeVariable)
                {
                    ApplicationArea = All;
                    Caption = 'Some Variable';
                    ToolTip = 'Init Value = true';
                }

            }
        }

        trigger OnOpenPage()
        begin
            SomeVariable := true;
            MESSAGE('OnOpenPage: %1', SomeVariable);
        end;
    }

    var
        SomeVariable: Boolean;
}

3. Expected behavior The Variable should be set to "true". When the user changes it to "false" it should stay that way for the run of the report.

4. Actual behavior Instead the OnOpenPage()-trigger is run again when running the report. This re-initializes the variable and now this value is used for the report.

image

image

image

image

5. Versions:

Id : b0c41a2d-9ebe-4773-a22f-86bd69e75949 Name : ELSTER VAT Localization for Germany Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 5a0b41e9-7a42-4123-d521-2265186cfb31 Name : Contoso Coffee Demo Dataset Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 437dbf0e-84ff-417a-965d-ed2bb9650972 Name : Base Application Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 8c972578-fe72-4aa5-ae51-cc5575fef2ea Name : Send To Email Printer Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : e6328152-bb29-4664-9dae-3bc7eaae1fd8 Name : Email - Outlook REST API Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 68e13fa3-217a-4be0-9141-99e5bf0ca818 Name : Email - SMTP Connector Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 66562109-c5eb-437e-bb8b-f4809337714e Name : OnPrem Permissions (DACH) Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 3d5b2137-efeb-4014-8489-41d37f8fd4c3 Name : Late Payment Prediction Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 114e4e19-182b-42e2-b5a9-91d8b8ee8ce1 Name : _Exclude_Email Logging Using Graph API Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : c1335042-3002-4257-bf8a-75c898ccb1b8 Name : Application Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 7961e9dc-a8e5-49b1-839b-3a78803a4cb8 Name : Troubleshoot FA Ledger Entries Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 40860557-a18d-42ad-aecb-22b7dd80dc80 Name : Permissions Mock Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : bae453ed-0fd8-4416-afdc-4b09db6c12c3 Name : WorldPay Payments Standard Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 10cb69d9-bc8a-4d27-970a-9e110e9db2a5 Name : _ExcludeAPIV2 Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 16319982-4995-4fb1-8fb2-2b1e13773e3b Name : AMC Banking 365 Fundamentals Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : aceb66c8-472e-437c-81d3-27e6c07d0f14 Name : Email - Microsoft 365 Connector Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 4b1c41f9-7a13-4122-d521-2465194cfb32 Name : Contoso Coffee Demo Dataset (DE) Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 8fc50dfb-d338-4fd9-9499-5e44cc8cbf50 Name : Email - SMTP API Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 8afe7b40-8c87-4beb-ada0-451d1761bf95 Name : _ExcludeAPIV1 Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : d09fa965-9a2a-424d-b704-69f3b54ed0ce Name : Payment Links to PayPal Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 2654d7e7-9afd-4947-9e02-6bb8f3e0cd04 Name : Universal Print Integration Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 7a129d06-5fd6-4fb6-b82b-0bf539c779d0 Name : _Exclude_Bank Deposits Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 8b3609cf-3947-44c3-9f20-ce6edc6da33f Name : _ExcludeClientAddIns Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : a53a4bb0-aa53-8ff8-77d6-fe3388db0eb8 Name : Recommended Apps Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 79b1a79a-2f66-4736-bc1b-8abb3537eb51 Name : Simplified Bank Statement Import Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 5f92e0d5-a60e-435f-ae85-71ec28dd3e41 Name : _ExcludePlanConfiguration Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : c526b3e9-b8ca-4683-81ba-fcd5f6b1472a Name : Sales and Inventory Forecast Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : c512d720-63b9-4b26-b062-a0c09b4ed322 Name : Company Hub Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : b7174aae-753c-4e71-bacb-d973995dce5e Name : _Exclude_ReportLayouts Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 08d69832-9231-429e-be2c-8bab2c96905b Name : Email - Current User Connector Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 23de40a6-dfe8-4f80-80db-d70f83ce8caf Name : Test Runner Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 2a89f298-7ffd-44a5-a7ce-e08dac98abce Name : Essential Business Headlines Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 75f1590f-55c5-4501-ae63-bada5534e852 Name : Performance Toolkit Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 63ca2fa4-4f03-4f2b-a480-172fef340d3f Name : System Application Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 7819d79d-feea-4f09-bbed-5bbaca4bf323 Name : Data Archive Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : ec255f57-31d0-4ca2-b751-f2fa7c745abb Name : Shopify Connector Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : e7320ebb-08b3-4406-b1ec-b4927d3e280b Name : Any Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : dd0be2ea-f733-4d65-bb34-a28f4624fb14 Name : Library Assert Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 5095f467-0a01-4b99-99d1-9ff1237d286f Name : Library Variable Storage Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 9856ae4f-d1a7-46ef-89bb-6ef056398228 Name : System Application Test Library Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

Id : 5d86850b-0d76-4eca-bd7b-951ad998e997 Name : Tests-TestLibraries Version : 20.3.42673.43026 Publisher : Microsoft ExtensionType : ModernDev Scope : Global Tenant :

dzzzb commented 2 years ago

I have run into this. I agree that it is surprising. I suspect it not (well-) documented. But I also doubt it can be changed now, without possibly breaking code for other developers, who have ended up (deliberately or not) relying on the current pattern of when the trigger is run. I also suspect it will be closed as it is an issue in the platform/documentation, not the language/compiler.

pri-kise commented 2 years ago

@JulianTillmann this is by design. You should have a look at the following documentation about the multiple preview feature: https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-report-triggers?tabs=current%2Crdlc#modes

On this page it is explaned how it works and what can be solutions. https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-report-triggers?tabs=current%2Crdlc#multiplepreview

thloke commented 2 years ago

Closing as by design (as well as being out of scope for this repo, we don't handle the running of triggers here).

navdotnetreqs commented 5 months ago

"This is a problem when trying to initialize variables for the request page. Any value changed by the user in the request page it re-set when the report starts."

Ran into this problem as well.

@JulianTillmann did you manage to circumvent this limitation caused by bad design some other way?

navdotnetreqs commented 5 months ago

"This is a problem when trying to initialize variables for the request page. Any value changed by the user in the request page it re-set when the report starts."

Ran into this problem as well.

@JulianTillmann did you manage to circumvent this limitation caused by bad design some other way?

Replying to myself, you can do this

trigger OnOpenPage()
        var
            ReportsSetup: Record "Reports Setup";
        begin
            if not BooleansSet then
                if ReportsSetup.Get() then begin
                    BooleansSet := true; // Circumvent MS feature https://github.com/microsoft/AL/issues/7112
                    HideInvoiceDiscount := ReportsSetup."Hide Invoice Discount";
                    HidePaymentTerms := ReportsSetup."Hide Payment Terms";
                end;
        end;

But you must add BooleansSet to the request page (you can put visible=false) otherwise it's value will not be retained.

JulianTillmann commented 5 months ago

@nav

"This is a problem when trying to initialize variables for the request page. Any value changed by the user in the request page it re-set when the report starts."

Ran into this problem as well.

@JulianTillmann did you manage to circumvent this limitation caused by bad design some other way?

It's been a while and I'm not sure where I implemented it, but I think I used a singleinstance codeunit or setup table like yourself