AL icon indicating copy to clipboard operation
AL copied to clipboard

Global Variable on Page Extension is inaccessible due to its protection level

Open ccorreia83 opened this issue 7 years ago • 11 comments

Describe the bug I'm making a simple page extension, and when I try to access to a global variable of original page, there's no access.

To Reproduce

  1. Create page extension of "Document Attachment Details", if using FromRecRef to any new function it gets: 'FromRecRef' is inaccessible due to its protection level

AL Code to reproduce the issue

Expected behavior I would expect to access to a global variable of a page in a page extension.

Screenshots Not aplicable

5. Versions:

  • AL Language: 4.0.191880
  • Business Central: BC 15 wave 2 (15.0.36560.36649)

ccorreia83 avatar Oct 28 '19 14:10 ccorreia83

I saw a closed issue similar to this telling this kind of problem should be solved in Wave 2. But it seems problem is still the same? (https://github.com/microsoft/AL/issues/593)

ccorreia83 avatar Oct 28 '19 14:10 ccorreia83

Yes this feature should work. If you declare globals in the global var section of an AL file protected var myInteger : Integer Then you should be able to access it in a page extension.

kalberes avatar Oct 29 '19 10:10 kalberes

Simple example: page 1173 "Document Attachment Details" It has the global variable FromRecRef: RecordRef; Or even: SalesDocumentFlow: Boolean;

If I create a pageextension 50121 "Doc. Attach. Details Ext" extends "Document Attachment Details"

And use FromRecRef on page extension I get the error: 'FromRecRef' is inaccessible due to its protection level

If I create a global var in my pageextension with name FromRecRef. I don't have the error anymore, but FromRecRef doesn't have any value.

So how it should be used, so we have access in a pageextension to a global variable of the page?

ccorreia83 avatar Oct 29 '19 11:10 ccorreia83

Hi @ccorreia83. As @kalberes suggested, use in your example: protected var SalesDocumentFlow: Boolean; then it becomes visible in the extensions. The same for procedures. For details please see https://docs.microsoft.com/en-us/dynamics365-release-plan/2019wave2/dynamics365-business-central/access-modifiers.

AndreyKorepanov avatar Oct 29 '19 15:10 AndreyKorepanov

Hi @ccorreia83. As @kalberes suggested, use in your example: protected var SalesDocumentFlow: Boolean; then it becomes visible in the extensions. The same for procedures. For details please see https://docs.microsoft.com/en-us/dynamics365-release-plan/2019wave2/dynamics365-business-central/access-modifiers.

This means that original page has to have the variable declared as protected, so it can be accessed from a page extension.

But if I'm making a page extension if because I want to retrieve a variable of a standard page that I cannot declare the variable as protected.

So from my page extension I need to access to a variable that is in the original page that isn't marked as protected, so this way can't be used.

Or I'm seeing something differently?

ccorreia83 avatar Oct 29 '19 15:10 ccorreia83

I have the same question as @ccorreia83. My sandbox site is on the cloud. Create extension to extend "Payment Journal" page. action(GenerateEFT2) { ApplicationArea = Basic, Suite; Caption = 'Test Generate EFT File'; Enabled = NOT (AMCFormat = TRUE); Image = ExportFile; }

And Visual Studio Code directly shows following error and does not allow to compile and publish. AMCFormat' is inaccessible due to its protection level,

Do I need to re-declare AMCFormat again in my code?

Ray-Bao avatar Nov 03 '19 01:11 Ray-Bao

I have the same kind of problem. I want to change or read the default global variable CurrentDocNo of the "General Journal" page. But I could not find an solution. I could even add the same variable and it has no effect. Any Ideas or something else I could do? (could be a problem while I pray here at my colleagues "DO NOT CHANGE THE BASE APP")

pageextension 50005 "GeneralJournalTEST" extends "General Journal" { layout { // Add changes to page layout here } actions { // Add changes to page actions here } trigger OnOpenPage() begin CurrentDocNo := 'G00013'; end; trigger OnAfterGetCurrRecord() begin Message(CurrentDocNo); end; var CurrentDocNo: code[20]; }

aptMattKoe avatar Mar 24 '20 16:03 aptMattKoe

Same problem here as @ccorreia83, @Ray-Bao, and @aptMattKoe . I'm trying to extend Page 950 and make use of global variable TimeSheetHeader in my extension. VS tells me "'TimeSheetHeader' is inaccessible due to its protection level."

Wasn't the intention to make global variables in standard pages available in extensions? Or not? if not, what are the risks?

grantbrimhall avatar May 17 '20 20:05 grantbrimhall

Global variables will be accessible if they are marked as "protected". By default, they are not accessible from page extensions. This was done because these pages must be designed for extensibility. Please file file issues on https://github.com/microsoft/ALAppExtensions for additional extensibility.

atoader avatar May 21 '20 14:05 atoader

Hi. thank you for the reply. I'm not sure that I follow. if base application pages are to be designed for extensibility, making global variables of base application pages not accessible seems to be contrary to your stated design/objective. what am I not understanding?

grantbrimhall avatar May 21 '20 18:05 grantbrimhall

base application pages are to be designed for extensibility the future tense is the correct one. They will have to be designed for extensibility, they are not extensible at the moment. Please file a request in the GitHub repository mentioned above. The language and the extensibility of the Base Application are two separate concerns.

atoader avatar May 22 '20 13:05 atoader