AL icon indicating copy to clipboard operation
AL copied to clipboard

Access to Global Temporary variable in page from Page extension

Open andreilungu opened this issue 8 years ago • 2 comments

Version 13.0.22070.0

PAGE 161 "Purchase Statistics"

I am trying to convert custom modification made to this page to a Page Extension.

At the end trigger OnAfterGetRecord we have added a function that does some calculations and copies some values based on the values from global variable "TempVATAmountLine"

The issue is that in the Page Extension we don't have access to this global temporary variable. issue access global var

We have this situation multiple times, not only at this example and sometimes we filled another temporary in the page extension but it is bad practice (duplicating code, executing similar code multiple times), so we want to ask you if there is a better workaround for this ?

Our idea is if you can add an Event publisher in page 161 at the end of OnAfterGetRecord trigger that will contain a by reference parameter of the global variable "TempVATAmountLine". In this way if we subscribe to that event we could have access from the page extension to that global variable that contains values calculated in the page.

Thanks, Andrei Lungu

andreilungu avatar May 30 '18 09:05 andreilungu

Hello,

I tested with the event added in the new build, but now I think that this solves the issue only partially:

  • As I said in the previous message, we need to copy some values based on the values from global variable "TempVATAmountLine" to another global variable from the page extension called "TempVATAmountLine2".
  • The issue now is because of the limitation that an event subscriber can be added only in a Codeunit. So I create a new codeunit, subscribe to the OnAfterCalculateTotals publisher you added in page 161 in the new build and copy the needed values in a global variable "TempVATAmountLine2" in the newly created codeunit.
  • The "TempVATAmountLine2" cannot be retrieved from the Codeunit to the page extension (where we need to use it later on). (It is possible only if we make the codeunit SingleInstance but we want to use it like this only as a last option...)

We need the "TempVATAmountLine2" in the page extension because we use it later on to populate a custom added subform.

Please see how it was in 2017 version: customform populate and use tempvatline2

How do you recommend to implement this (preferably without Single Instance Codeunit) ? subscriber codeunit

Event Subscribers cannot be created in a page: event subscribers cannot be created in a page

andreilungu avatar Jun 19 '18 11:06 andreilungu

The same issue happens also for page 401 Purch. Credit Memo Statistics. The scenario is the same with global variable "TempVATAmountLine".

bogdan81GitHub avatar Jun 20 '18 15:06 bogdan81GitHub