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

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.