Skip to main content

Microsoft Dynamics NAV 2016 - How To Use Integration Or Business Events.

Hi All,

Recap -"We Have seen how to use the Trigger Events. As its a Trigger Event we don't Need to Publish or Declare It. We Just Saw how to Subscribe Trigger based Events."

If you are missing the Story, Refer Table of Index.

As we already know that there are Three Things Related to Events -
 > Publish The Event.  
 > Raise The Event.
 > Subscriber The Event.

In This Article We will Discuss Integration / Business Events.

First Let's understand Why I Said Integration Or Business Events? Are they same?
> If yes Why two names?
> IF No Why Saurav is trying to cover them in same article?

This is what Microsoft Says About Business Events.

A business event is a custom event that is raised by C/AL code. It defines a formal contract that carries an implicit promise not to change in future releases. It is the expectation that business events are published by solution ISVs, including Microsoft.

And This is What Microsoft Says About Integration Events -
An integration event is also a custom event that is raised by C/AL code, like a business event, except that it does not carry the same promise of not changing, nor does it have the restriction not to expose implementation details.

So Actually the Execution Remain Same But Business Events Holds a Implicit Promise that they will not change in Future Release.

Let's Start with Simple Explanation of Publishing an Event and Raising An Event. In Simple Words this Approach, Suggest to Write as less code as possible on the standard Objects and use More of the Function Approach.

If you are one of those developers who always use a seprate Function while doing any changes this it kind of same thing. Suppose I Want to write 10 Lines of code at a Standard Process May be Table Field Validate or During Codeunit Processing, I Just create a function for those 10 Lines and call that function at the required Place.

This also answers the question that you might have during discussion of Trigger Events - What if I want to Write a Code in between the standard Table Field Functions?

Now for Understanding these two things related to Events lets discuss some changes in Customization Done Earlier.

Customer says that During Posting of Sales Order The "Latest Revision No." will be checked again if a New Revision is Created between Creating of Sales Order and Posting of Sales Order then the Invoice Should have New Revision No.

The Invoice Lines are created using TransferFields as we all know but there is a function in Sales Invoice Lines, which does this Transfer of Data. So we will do the customization Here. Let's Add Same Field "Latest Revision No." in Sales Invoice Line with same Id as of Sales Line.

How To Publish An Event?
> Create a New Codeunit 60001 - My Custom Event Publisher.
> Now We Need to Publish an Event, Create a New Function "UpdateRevisionNo" with Below Properties -
  > Local - NO
  > Events - Publisher
  > EventType - Integration
  > IncludeSender - Yes

The Event is Published, Let's add the Parameters as Var to the Published Events of Table "Sales Invoice Line". You cannot add any Code in the Publisher, only comment be the part of Publisher as shown below.

How To Raise An Event?
Raising an Event is Equivalent to Calling the Function. So let's Call the Published Event in the standard Navision Code. As the Transfer is Happening in Function InitFromSalesLine, so I added a Hook Point to the Published Event in the Function as shown Below.

How To Subscribe An Event?

Subscribing the Event Remain Same as we Did in for Trigger Events.

I Decide to use the Same Codeunit 60000 for all subscription that I do for customer. In this way i Make it easy for anyone to work and find out where all I have customized the standard Process.

It also helps during upgrade as if any changes I want to do I have to do in a single object.

> Design Codeunit 60000.
> Add a Function DuringPostofSalesOrder with Below Properties -
  > Event - Subscriber
  > EventPublisherObject - Codeunit My Custom Event Publisher
  > EventFunction - UpdateRevisionNo

As Shown Below My Subscriber is Ready to be Used. Let's write the Code to Update Revision No. If Required.

Let's Add a New Revision and Post an Order with Old Revision no. on Lines and see the Impact.

Hope Now it should be Clear How Events and Subscribers work in Microsoft Dynamics NAV 2016. Let me know if you have any questions.

If required you can download the Related Objects from SKYDRIVE.

File Name - Microsoft Dynamics NAV 2016 - Event Demo (Final Objects).rar

Your Feedback on articles are much Awaited.

Stay Tuned For More.

Saurav Dhyani


  1. Hi Saurav Thanks for your Blog. Just a question How to Write a Code in between the standard Navision Code. In the above example we are still changing the standard Navision code In INITfromSalesLine Function in table ? while upgrade this will be the issue as we have added our customized code which Microsoft wants to avoid. please let me know your views

    1. Yes that is true. This article is pretty old and Events were new at that time.
      I totally agree to your point this is not the right way as of today. Please refer to new series that i recently completed about futuristic C/AL where i put forward my current views and let me know how you find those thoughts.


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.

NAV 2013 Upgrade Part III - Data Upgrading.

Hi all, As per agenda we need to discuss the data upgrade in NAV 2013. The process is similar to what used to be till NAV 2009 R2 but with some changes. Let's start the process. Remember -  1) You can only upgrade a database to NAV 2013 from NAV 2009 SP1 / R2 SQL Only. 2) The Synchronization of users with SQL Server is no more required.