Skip to main content

Does Pass by Value Work in Businesses Central AL?

 The difference between pass-by-reference and pass-by-value is that modifications made to arguments passed in by reference in the called function have effect in the calling function, whereas modifications made to arguments passed in by value in the called function cannot affect the calling function.

And it’s like that in any programing language, right? Well, no not in every case with Businesses Central AL, using a Variant Data Type and Record Ref’s have a little bug. Let’s check it out.

Let’s define a RecRef and assign it to a Sales Line table for example and create a function that accepts input parameter Passed by value of type Variant, you can also try with RecordRef.


Note that SourceRecordRef and SourceFieldRef are local Variables. Assigning Field Ref and then reusing the SourceRecordRef again to get the Customer table will change input parameter to a customer even if it is passed by value. This will happen if the input parameter is RecordRef also.

And in documentation it is stated that “If one RecordRef variable is assigned to another RecordRef variable, then they both refer to the same table instance.” But why it is changing pass as value to pass as reference?

So, the best, practice: “you should Close the record ref before changing the assignment to another table”. And if you do that the problem will be solved. Nevertheless, this does not change the fact that the Parameter pass-by-value acts like a pass-by-reference, which should never happen, in any case!

Please also note that this is an isolated example problem originated when I was using standard Codeunit Data Type Management.

It should be like this:

You can also checkout Git Repository where I played a bit to determine what is happening: SarkeSrb/RecRefBug (github.com)

Additionally, I have reported an issue to Microsoft you can track the issue on link below, until than be sure to Close RecordRef before assignment to other Record to avoid the problem.

Pass by Value becomes, Pass by Reference when using Variant or RecordRef as Parameter and make assignments to other Records · Issue #7312 · microsoft/AL (github.com)


Comments

Popular posts from this blog

Prepare For Certification - MB-820: Microsoft Dynamics 365 Business Central Developer

And finally, after around 10 years there is a certification again for Business Central Developers. Since there is no official book there are few ways to prepare by using online resources. Do not take this exam for granted event the old one was not easy even for the experienced developers :D nevertheless I hope that following links will help you prepare as best as possible. Review the study guide: Study guide for Exam MB-820: Microsoft Dynamics 365 Business Central Developer | Microsoft Learn Complete the training: Course MB-820T00---A: Dynamics 365 Business Central Developer - Training | Microsoft Learn There are also instructor materials available on GitHub that you can access for free: MicrosoftLearning/MB-820-Business-Central-Developer-Certification (github.com) What can I say more happy preparation 😊

Report Region Format and Language finally changeable without Developer intervention

  Report Region Format and Language finally changeable without Developer intervention Did you notice? As of BC23 reports have new settings on the request page that can set the output of the report to the desired Region Format and print them in other languages! New advance functionality is designed to override default settings from my settings and customer it means you can now print report in any language (if you have it installed) and in any desired format. So, let’s take a quick look at it.  Regular quote base system settings: Language: German (Germany) Format region: Italian (Switzerland) WOW! I know strange combination nevertheless superb outcome! And it works in RDLC and Word layouts! And for your consideration this will work only and only if you do not specify a specific format for the field in RDLC. So, in RDLC field has to have format set from the dataset.

How to? Integrate into new posting routine V19 – Businesses central.

Since V19 Microsoft has introduced a new posting interface. Depending how you concepted your integration in to a posting routine you might have to refactor your code. Let’s start by looking into what has changed. What we have now from Microsoft is a codeunit 825 "Sales Post Invoice Events" in this codeunit you can find a bunch of publishers that will enable you to integrate into a function from codeunit 80 (for newbies this is the codeunit that handles posting in Sales transferring Sales Order to a Posted Sales Invoice for example). To integrate your logic into posting for any new application you are developing you can use these publishers and find a specific point that suits you the most. Alternatively, you can implement interface "Invoice Posting" if it suits you better. Another change is that the table 49 "Invoice Post. Buffer" is discontinued. Yap! A little bit about this table, in general it is a preparation table for the lines in order for them...