Skip to main content

MSDYN365BC - AL Development 07 - Add More Subscriber in Codeunits For Ledger?

Hi Readers,

I hope you all are following this series and followed and completed what we have discussed till now. If you are new to this then Please Refer Table of Index.

We are about to finish this series with 2 more articles.

In this part of this extension as per customer, the requirement is had the Sales Header Source Code to be updated in Item Ledger Entries also.

As NAV Experts all my readers know how to transfer data from Sales Header to Item Ledger Entries that is -
1. Data from Sales Header move to Item Journal Line.
2. From item, Journal data move to Item Ledger Entries.

With that been said, we will require to have "Source of Sales" field in Item Journal Line and Item Ledger Entries.

Let's build two table extension to start with -

Add two new files with name as per our standard -

  • SDH_TableExt_50003_ItemJnlLineExt.al
  • SDH_TableExt_50004_ItemLedgerExt.al
And add fields, in both table extension as shown below.


Next, I am sure that we all want to see the value to the user in Item Ledger Entry page, so let's add a page extension with the name - SDH_PageExt_50003_ItemLedgerEntriesExt.al, as shown below.


Now we need to identify a Published event that can do these two things -
  1. Transfer value of Source of Sales from Sales Header to Item Journal Line During Posting.
  2. Transfer value of Source of Sales from Item Journal line to Item Ledger Entry during Posting.

As C/AL, experts we know where these events were supposed to be placed i.e. -
  1. Codeunit 80 Sales-Post.
  2. Codeunit 22 Item Jnl.-Post Line.

But Code is changing for a while and following are changes - 

1. During Sales order posting in Codeunit 80, Item Journal line record is inserted using a function in Table 83 "Item Journal Line" - CopyFromSalesHeader where Microsoft has added an event "OnAfterCopyItemJnlLineFromSalesHeader" that can be Subscribe to transfer custom values as shown below.


2. Item Ledger Entries are inserted via Codeunit 22 using the function "InitItemLedgEntry". Microsoft has added an event "OnAfterInitItemLedgEntry" that we can Subscribe to Transfer Custom values as shown below.



Lot's of theory, Let's add those two subscribers and respective code in our subscriber Codeunit created in the last article.

1. Add new subscriber in the same Codeunit using snippet teventsub to get the skeleton of the subscriber as shown below.



Lets assign parameters -

  • Object Type - Table.
  • Database::"Item Journal Line"
  • OnAfterCopyItemJnlLineFromSalesHeader - Event that we want to subscriber.
  • '' - This parameter only applies to Table Fields.
  • TRUE
  • TRUE
  • TransferSourceofSalesToJournalLine - Function Name that we want to name the function.

Add all available parameters to Function / Procedure (as discussed in last article).

2. Add new subscriber in the same Codeunit using snippet teventsub to get skeleton of subscriber as shown below.

Lets assign parameters -

  • Object Type - Codeunit.
  • Codeunit::"Item Jnl.-Post Line"
  • OnAfterInitItemLedgEntry - Event that we want to the subscriber.
  • '' - This parameter only applies to Table Fields.
  • TRUE
  • TRUE
  • TransferSourceofSalesToLedger - Function Name that we want to name the function.

Add all available parameters to Function / Procedure (as discussed in last article).

The Newly added subscribers with the code will look like as below.



With this, the functionality that customer asked for is ready to be used. In Next article, we will test this functionality after Publishing modified extension.

Stay Tuned for more and please add comments if any questions/suggestions.

Regards,
Saurav Dhyani
www.sauravdhyani.com

Comments

  1. No issues, easy to follow. Just new to VS codes and all these AL syntax. Great Job Saurav

    ReplyDelete
    Replies
    1. Thanks for the comment @ibrahim. Great to hear that you liked the content.

      Delete
  2. Thanks a lot....This blog helped to fend off the fear of new changes in NAV/BC.

    ReplyDelete
  3. This was very helpful to me, thank you for explaining it so well.

    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.