![]() |
#1 |
Участник
|
waldo: Protected Variables
Источник: https://dynamicsuser.net/nav/b/waldo...cted-variables
============== “Protected Variables” might not be a familiar topic in the Business Central world. It was at least not that familiar to me ;-). So I wanted to make a small post to make this more known in the community, so that at least you are aware that it exists .. and it might give you some more extensibility options that you might not have considered.. . The concept is simple: protected variables are variables that you can access from a dependent extension. So .. thinking about this .. it actually has only any effect on extension object, because that way, you’re kind of “in” the object. So, we’re only talking about extension-objects being “table extensions”, “page extensions” and “report extensions”. I’d normally say that you can find more information on Microsoft Docs: Protected Variables – Business Central, but quite honestly, there’s not *that* much information on there.. . Now, you might know I’m not particularly fan of “global variables” as such, and a protected variable, is actually a global variable, that you extend outside the scope of the extension .. so as such, you make it even more global than it would be as a normal global var ![]() ![]() How does it work? Well, I created my own example which you can find here on GitHub: waldo1001/blog.ProtectedVariables. It has a MainApp, and a Dep(endant)App. And you can see that in the objects, I declared a normal var, and a protected one, like this: ![]() ![]() ![]() When you browse through the BaseApp, you find about 264 occasions where Microsoft has declared protected variables. Obviously in the objects that are extendable. At least “mostly”. There are some codeunits with protected variables as well – which I have no idea why that is. Afaik, that totally doesn’t serve any need. If you have a clue – please put it down in the comments ![]() Anyway, from a short analysis for browsing through these protected variables, you can clearly see some typical usages, like:
![]() So, keep in mind this is also an option for you: if you need access to table/page/report-variables from the base app, just file your own issue, and Microsoft will respond fairly quickly. And if you’re an ISV, you can foresee (and should think about) your own protected variables if that would make sense for your app ;-). Open Questions While writing this post, I did come across some odd things as well. Like the already mentioned protected vars on codeunits which I don’t have a clue for what they are there for. But the same for protected procedures (which is not *really* the content of this post). Well, any of those (protected vars or protected procs) in a codeunit, I have no idea why that would be useful. It doesn’t do anything really expected:
![]() ![]() If anyone can comment on this, or have any more insight – you’re more than welcome to comment below ;-). Here is a twitter-thread about the same topic as well: #bcalhelp me out here … I stumbled on this protected variable in a codeunit in de baseapp (codeunit 333 "Req. Wksh.-Make Order"). Источник: https://dynamicsuser.net/nav/b/waldo...cted-variables
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|
|
|