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

Created on 28 Oct 2019  Â·  11Comments  Â·  Source: microsoft/AL

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)

Most helpful comment

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?

All 11 comments

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)

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.

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?

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.

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?

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?

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];
}

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?

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.

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?

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.

Was this page helpful?
0 / 5 - 0 ratings