Skip to main content

MSDYN365BC - Futuristic CAL Development - Customize Base Code 1.

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 about 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.



Let's add the actions in Page Chart of Accounts as shown below.


And similar action in G/L Account Card as shown below.


Now the Next part of customer requirements is to populate Expense Code in Purchase order Page when a G/L Account is selected. For that let's add the field Expense code in Purchase Line Table and Purchase order Subform, as shown below.


Or so last part of customer requirements that we will discuss in this article to have written that custom code which will pull "Expense Code" from G/L Account Card and populate it in Purchase Line.

As all we are C/AL Experts, let's see in Table 39 what happens when user key in the number Field.

  • OnValidate Trigger on No. field has a case Statement which calls different functions based on Type. We are only concerned about CopyFromGLAccount.
  • If we move that function CopyFromGLAccount we will see the last line in Function which says "OnAfterAssignGLAccountValues(Rec,GLAcc)"
  • If we navigate to that function, its a diffrent which which have no code and Function starts with the word [IntegrationEvent]


What we see in Line No. - 4793 above is an Integration Event that we will subscribe for our custom code.

What we would have done in Old C/AL Way?
We would have added one single line of code in CopyFromGLAccount function, which will look something like - "Expense Code" := GLAcc."Expense Code";

How to Do that in Future?

  1. Create a New Codeunit. I am creating codeunit 50000.
  2. Next, I will create a function in Codeunit called "TransferExpenseCodeToPurchLineFromGL"
  3. Next is we will set the following properties - 
    1. Event - Subscriber.
    2. EventPublisherObject - Table 39.
    3. & EventFunction.

If you lookup EventFunction - You will same Integration Event available that we see in the last step.



Click ok to Next message and We will see that few parameters are added in function and Subscriber is added in the function Name.


If we look function closely - Purchase Line variable is passed as Reference so we will be able to plug our code easily as above.

To understand How Execution will occur is like this - 

When System Executes Code in Purchase Line and Code will reach to line No. 2652 and then execution will move to custom Codeunit and then will come back in Table 39.

  • Purchase Line    - Line No. 2652.
  • Codeunit 50000 - Line No. 2653. (actual line No. 6)
  • Codeunit 50000 - Line No. 2654. (actual line No. 7)
  • Codeunit 50000 - Line No. 2655. (actual line No. 8)


In Next article, we will discuss - 
  • What we did in this article? 
  • what is Integration Event? 
  • Who can write it and how it executes?
Hope it makes sense, Stay Tuned for More!. Add your views as the comment to this article.

Regards,
Saurav Dhyani
www.sauravdhyani.com

Comments

  1. Hi Saurabh,If we have more then one Subscriber functions for the same EventFunction then what is the execution priority? I mean sequence of Subscriber functions.

    ReplyDelete
    Replies
    1. @Madhu, As per Microsoft there is no defined execution priority. If you test it then its based on Codeunit ID and then the Function position in the codeunit.

      Delete
  2. Dear Dhyani,Thanks for the information.

    ReplyDelete

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.