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

VIEW SERVER STATE permission on SQL Server?

Hi all, Sometime While trying to Login into a database we face an error message as shown below. --------------------------- Microsoft Dynamics NAV Classic --------------------------- You cannot start Microsoft Dynamics NAV Classic because you do not have the VIEW SERVER STATE permission on SQL Server. Contact your system administrator. --------------------------- OK    ---------------------------

RTC Report It is not possible to instantiate the Visual Studio bridge.

Hi all, As a Navision developers I have Multiple Versions of Navision running in single Machine. As discussed Earlier in the post how to run multiple Version of RTC in single machine. So my machine have following details for RTC Versions - NAV 2009 R2    - is installed. NAV 2009 SP1  - is copied at C:\Program Files (x86)\Microsoft Dynamics NAV\60\NAV 6.0 SP1 IN\ NAV 2009         - is copied at C:\Program Files (x86)\Microsoft Dynamics NAV\60\NAV 6.0 IN\ This approach has been working great for execution of Classic and RTC Clients. However, after installing Dynamics NAV 2009 R2, if i tried to view the Layout for an NAV 2009 SP1 Report i was getting the following error: ---------------------------  Microsoft Dynamics NAV Classic  ---------------------------  It is not possible to instantiate  the Visual Studio bridge.  ---------------------------  OK    --------------------------- After searchi...

NAV 2013 R2 - Cumulative update 12 Released.

Hi all, Please find below the details of  Cumulative Update 12 released for Microsoft Dynamics NAV 2013 R2. Title - Cumulative Update 12 for Microsoft Dynamics NAV 2013 R2 Build No. - 38053 Release Date - October, 2014 Local Version Included - AU, AT, BE, CH, DE, DK, ES, FI, FR, IS, IT, NA, NL, NO, NZ, SE, UK, RU Download Link Note: Implementing this cumulative update will require a database conversion unless you have already implemented update rollup 5.