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

Welcome - Microsoft Dynamics 365!

Hi All, In this article we will discuss the new introduced member of Dynamics Family. Yes you heard it correctly, one more new member with Name "Microsoft Dynamics 365" . #ProjectMadeira   #Dynamics365

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 - 

NAV 2013 Credential Type - How to Use?

Hi all, Please do these activities when you have time, its a long activity and i would suggest do all activities in one go. So be clam and lets start. For NAV 2013 R2 Refer Here. For NAV 2016 Steps have been Reduced Please Refer Here. I have installed NAV 2013 and its work great with my windows credentials. I was checking the service console (Microsoft Dynamics NAV Administration) in NAV 2013 and found out that Credentials Type have multiple Options.