Skip to main content

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 to be grouped. GL lines are grouped standardly by Line Type, G/L Account, Gen. Bus. Posting Group, Gen. Prod. Posting Group, VAT Bus. Posting Group, VAT Prod. Posting Group, Tax Area Code, Tax Group Code, Tax Liable, Use Tax, Dimension Set ID, Job No., Fixed Asset Line No, Deferral Code and last but not least Additional Grouping Identifier. And by now you only had this field to use for any additional grouping that you would need. This of course presented a problem since there can be many applications modifying this field and that creates a mess in a posting routine, so it had to be changed let’s see how.

There is a new posting buffer table 55 "Invoice Posting Buffer" and the major difference is the Primary Key, the Primary Key has been changed and now it is just one Field "Group ID" of Type Text and there is a function that builds this primary key called BuildPrimaryKey(). At the end of this function there is a publisher OnAfterPrepareSales(Rec) which enables you to add your own grouping field value. In order to do this, you first need to extend the Invoice Posting Buffer table and add your field.

Okay I know too much text. Let’s make it like this, I will show how to do this by covering two most common requests I had over the years. Transfer value from the Sales Header to GL Entry and Customer Ledger entry and Group and transfer Value from the Sales Lines to GL Entry. And I won’t use codeunit 825 "Sales Post Invoice Events" or implement "Invoice Posting" interface. I will go deep into a fundament. 😊

So, we add fields to Sales Header, Sales Lines, General Journal Line, Customer Ledger Entry, G/L Entry, Invoice Posting Buffer.








And of course, add it to all related tables Sales Invoice, Archives with the same ID and TRANSFERFIELDS will do the rest.

You can look for the complete code in my GitHub repository (Link at the end of the Page).

Ok let’s move on now we need to transfer all those fields values, so we subscribe to following events.


OnAfterPrepareSales – on Invoice Posting Buffer will transfer our value to the buffer so we can have a value for the grouping of the lines.

OnAfterBuildPrimaryKey – on Invoice Posting Buffer will add our value for the grouping in to the Primary Key and the rest will be taken care of by the standard code.

OnUpdateOnBeforeModify – on Invoice Posting Buffer we use to sum the values by the group. So, that is why I use “+=” so that the values of the groups are summed.

OnAfterCopyToGenJnlLine – on Invoice Posting Buffer is used to transfer the value of the line groups to the General Journal for the posting.

OnAfterCopyGenJnlLineFromSalesHeader – on Gen. Journal Line is used to take the value from the header field in order to be posted further.

OnAfterCopyGLEntryFromGenJnlLine – on G/L Entry table takes the values of our fields from the Journal to the G/L Entry.

OnAfterCopyCustLedgerEntryFromGenJnlLine– on Cust. Ledger Entry table takes the value of our field from the header from the Journal to the Cust. Ledger Entry.

And let’s review the result:

We create a sales order and fill the values:


Since as you can see in Subscribers above, I used the same field for grouping and summing, and we should expect to have lines split additionally in 2 groups 1 for the value of 5 with value 10, in GL Entry, and 1 for the Value of 15 with value 15 since we only have 1. And of course, value from the header will be transferred as well.

G/L Entry:

Customer Ledger Entry:


I know that this example does not make too much sense from the accounting perspective but feel free to use it however you like.

GitHub Link - SarkeSrb/NewPosting (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 😊

Story about Sorting - Microsoft Dynamics 365 Business Central

                Back in the days it was so easy, right? Design a table, add any field as a secondary key, and use it as you like to sort the data and do any calculation you like. Nowadays you have no access to base tables therefore the only option is to make extension of table definition. I won’t speak much about this since it is very nicely described in Microsoft documentation: Table Keys - Business Central | Microsoft Learn                 What I want is to review are a few possibilities of data sorting you can use in Business Central and, here is the nice part, regardless of are the fields part of the keys or not! Let’s start by creating a simple table for this purpose: And also, the page: Publish and enter some data for example like this: Notice that data is always sorted by primary key by default. So, let’s play. I will use actions to sort the data differently, so let’s add some actions to sort the date using the SetCurrentKey function: SetCurrentKey Function (Record) - Dy