AL icon indicating copy to clipboard operation
AL copied to clipboard

Why don't all system events provide access to global vars

Open SCreanor opened this issue 8 years ago • 4 comments

Similar to the Issue # 157, I would extend the question to why doesn't all system events such as OnOpenPageEvent for example provide access to all of the Global Vars on the page as part of the signature.

An example would be I need to add a field to a page, which I would like to show or hide based on a value configured elsewhere. To do this I create the Global Var and assign it to the field, and subscribe to the OnOpenPageEvent to determine what the setting for the global var should be.

The only problem with the above scenario stopping me from doing this is the system events do not give me access to any global variables, or the sending page itself, only the record the page is going to show.

To provide a comprehensive extensibility we should be able to have access to global vars as required. At this point we have a large add-on which is 99% extension compliant but because of this limitation we cannot get it across the line. If there is some other way to achieve what we need without having access to the global vars, that does not include having a new event added simply for this purpose I would be grateful to hear it.

SCreanor avatar Nov 09 '18 04:11 SCreanor

Because that's terrible, terrible design.

Global variables on an object should be none of our business as Extension developers. If you need access to a specific variable, request a (new) function expose and/or event.

If we get "GlobalVarAccess" (a thing that just by itself is an atrocity) on all events by default, we practically lock ourselves (and Microsoft) into a situation where MS is bound to not change them ... ever.

Every NAV object needs to have a clear and concise interface to the outside world. And that is achieved solely by public functions and events. It is up to the developer of the object (in this case MS) to define that API as extensible as possible. I don't want anyone to be messing around with the internals of my object.

PS: I cannot stress it often enough: the whole point of extensions is not to "make it work as it worked before, just in a different language" ... the point is to isolate your code and make it easily portable wherever you want. If you start to depend on object internals ... you are not isolating anything at all.

hemisphera avatar Nov 09 '18 10:11 hemisphera

I think you misunderstand the point of this question. I am not asking to have all the global vars added into the definition as required parameters. What I would like is the way it works now if I create my own publisher. I can allow access to global vars, in the publishing event, but when I add a subscriber, by default I only get the parameters I have chosen to add, and if I want to access the global vars, I need to add my own additional parameters to the subscription function, matching the name to the global var. This means I have to know what the global var names are to do this, and to be honest I have no interest in extending your extension, I am only looking at doing this for standard objects.

This is not bad design, this is a practical way to avoid having hundreds of events, simply to expose this variable, or that variable, etc.

As I requested if you have a design that allows me to achieve what I need, then tell me what it is, but simply calling it bad design is not very helpful. We must be able to access global vars of standard objects and Microsoft have already catered for this in manual events created in code, so all I am asking is why can we not have the same in system events, with the same design rules.

SCreanor avatar Nov 09 '18 10:11 SCreanor

Now this issue sounds more like an issue for our development tools team, as this isn't an (C/)AL question. Transferring issue.

JesperSchulz avatar Nov 22 '18 10:11 JesperSchulz

We do not want to expose all global variables across all event publishers. This would lead to too much coupling. Even worse, it would lead to coupling to state (through the global variables) that was originally not designed with being public in mind. The solution that we're considering is #593. Until then the only way to get access is to request specific app changes or new event requests.

StanislawStempin avatar Nov 23 '18 11:11 StanislawStempin