Skip to main content

MSDYN365BC - Futuristic CAL Development - Customize Base Code 3.

Hi Readers,

As discussed in the Last article, in this post we will continue with our Customer Requirements.

If you are new to this series then Please Refer Table of Index.

In this article, we will discuss adding custom code in base objects and what is the Futuristic way of adding code.

In your customer are Pre-2018 then you can use Hooks for those instances. (Refer Old articles to check how to use Hooks).



Next Part of Requirement - 

  • Expense Code is mandatory for all lines during the Posting of the Purchase order and will also check and Expense Code is not Disabled.
  • Expense Code should be available in General Ledger Entries.

As all we are C/AL Experts, we will try to write code in Codeunit 90 for the first requirement. We will write code in OnRun Trigger Before Posting Lines Begin as shown below.


As you can see in the above image -

  • Old Way - is the old way to write custom code by modifying base codeunit 90.
  • New Way - is the New way to write custom code with an Event in Base code.

Now as we have done in previous articles we are supposed to subscribe OnBeforePostLines Event in our Expense Codeunit and then write our custom code.

So let's start that -

1. Design Codeunit that we developed for placing all custom code related to this customization and add a function to subscribe to base events, as shown below.

  • Function Name - OnBeforePurchaseOrderPostLines
  • Event - Subscriber
  • EventPublisherObject - Codeunit Purch.-Post


And Rest is code that we all know as shown below.



Let's Start with Part 2 of requirement - Expense Code should be available in General Ledger Entries for Purchase Lines with G/L Account.  

How Standard NAV pass a field value posted to G/L Entries from Purchase order Lines?

  1. Codeunit 90 - Will move data from Purchase Line to Invoice Post. Buffer.
  2. Codeunit 90 - Will move data from Invoice Post. Buffer to Gen. Journal Line.
  3. Codeunit 12 - Will move data from Gen. Journal Line to General Ledger Entries.

As we all understand that as field data need to move in Invoice Post. Buffer and then to Gen. Journal Line and then to General Ledger Entries.

Let's add Expense Code field above-Listed Listed tables to move data. And also add "Expense Code" Field in General Ledger Entries Page as shown below.



Now as we have done the background work lets work toward code in Futuristic Way.

Codeunit 90 - PreparePurchase Which allow us to use Event to use for moving data from Purchase Line to Invoice Post. Buffer.



Codeunit 90 - CopyFromInvoicePostBuffer which allow us to use Event to use for moving data from Invoice Post. Buffer to Gen. Journal Line.



Codeunit 12 - CopyGLEntryFromGenJnlLine which allow us to use Event for moving data from Gen. Journal Line to General Ledger Entries.



Let's subscribe to Events that we identifed in our Expense Subscriber Codeunit.

Add three Functions for three Subscribers function as shown below -

  1. ExpenseCodeOnAfterCopyGenJnlLineFromInvPostBuffer
  2. ExpenseCodeOnAfterInvPostBufferPreparePurchase
  3. ExpenseCodeOnAfterCopyGLEntryFromGenJnlLine



Now last part which is quite simple for NAV Experts. One line of code in all three subscribers, as shown below.


In Next Article, we will test our solution and correct code if required during testing.

Let us know your thoughts as a comment to article. Hope it make sense!

Regards,
Saurav Dhyani

Comments

Post a Comment

Popular posts from this blog

BC 21 and Higher - PowerShell Cmdlet (Replacement of Business Central Administration).

Hi Readers, As discussed in last article about deprecating of Business Central Administration, there are few common actions that we use in administration till Business Central 20. For our on-prem customers, we will still require doing activities. As Microsoft suggest we need to start using PowerShell cmdlet.    Let's see how to do those via PowerShell, or Administration Shell. I will be keep adding commands as you comment to this article.

Send Mail with Attachment From Navision.

Hi all, We have seen how to save a report into PDF and how to send mail to a customer. Let's link these two post in one i.e. Mailing statement to a customer into PDF Format. This article is part of the Series. Please Refer  Table of Content here . If you have the old objects set let me brief you what I will be changing - 

MSDYN365BC - Data Upgrade To Microsoft Dynamics 365 Business Central on premises.

Hi Readers, We have already talked about the number of steps for upgrading to Business Central on Premises from different NAV versions. After that article, I received multiple requests for an article which list down steps for Data Migration. In this article, we will discuss steps of data migration to MSDYN365BC (on-Prem) from NAV 2017. For this article, I am considering a Cronus Demo Database without any customization. For an actual upgrade project, we will have to complete object merge using compare and Merge process. After the Merge Process, the next step is data migration. Let's discuss those steps. Direct Upgrade to Microsoft Dynamics 365 Business Central (on-Prem) is from following versions - 1. NAV 2015. 2. NAV 2016. 3. NAV 2017. 4. NAV 2018.