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.

Regards,
Saurav Dhyani

Comments

  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
    //
    MyCustomEventPublisher.UpdatRevisionNo(rec)
    //

    ReplyDelete
    Replies
    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.
      https://saurav-nav.blogspot.com/2019/01/msdyn365bc-how-to-do-futuristic.html

      Delete

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

RTC Report It is not possible to instantiate the Visual Studio bridge.

Hi all, As a Navision developers I have Multiple Versions of Navision running in single Machine. As discussed Earlier in the post how to run multiple Version of RTC in single machine. So my machine have following details for RTC Versions - NAV 2009 R2    - is installed. NAV 2009 SP1  - is copied at C:\Program Files (x86)\Microsoft Dynamics NAV\60\NAV 6.0 SP1 IN\ NAV 2009         - is copied at C:\Program Files (x86)\Microsoft Dynamics NAV\60\NAV 6.0 IN\ This approach has been working great for execution of Classic and RTC Clients. However, after installing Dynamics NAV 2009 R2, if i tried to view the Layout for an NAV 2009 SP1 Report i was getting the following error: ---------------------------  Microsoft Dynamics NAV Classic  ---------------------------  It is not possible to instantiate  the Visual Studio bridge.  ---------------------------  OK    --------------------------- After searchi...

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.