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

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

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.

Error After Restore SQL Backup of NAV 2013 Database

Hi all, we are facing a conman issue during restoring a SQL Database backup restored for NAV 2013. While Trying to run object from Object Designer we get below listed error (even the service is configured properly) - --------------------------- Microsoft Dynamics NAV Development Environment --------------------------- There are no NAV Server instances available for this database. You must ensure that a NAV Server instance is running and is configured to use the database before you perform this activity. --------------------------- OK    ---------------------------