Skip to main content

MSDYN365BC - Futuristic CAL Development - UnBoxing Integration Event.

Hi Readers,

Last article we subscribed an Integration Events. As promised in this post we will understand Integration Events in Base C/AL Code.

If you are new to this series then Please Refer Table of Index.

With this article, I will try to clarify all doubts and questions about Integration & Business Events.


This will help Developers to develop new Publisher if require or subscribing published Events. Let's discuss that in details.



What are Integration Events?
An integration event is also a custom event that is raised by CAL/AL code.
The main purpose of integration events is to enable the integration of other solutions with Dynamics 365 Business Central / NAV without having to perform traditional code modifications. It can also simply be designed-in hook points for external add-ons.

Who Can Publish Integration Events?
Microsoft, Solution ISV & Microsoft Partners Developers can Define Integration Events to provide a Hook for external parties without modifying the code.

Where we can Publish Integration Events?
You can only Publish Integration Events in the Code that you own.

  • Microsoft has already and will keep on adding Integration Events in Base NAV / AL Objects.
  • Addon / Solution ISV can only add Integration Events in Addon Range Objects. They are not allowed to add in Base NAV / AL Objects.
  • Microsoft Partners can only add Integration Events in Custom Object Range (50000..99999). They are not allowed to add in Base NAV / AL or Addon Base NAV / AL Objects. 

What Objects can be used for Publishing Integration Events?

We can Publish(add) new Integration Events in all CAL/AL objects other than - Query and Menusuite.

How can we Publish Integration Events?
Three Parts for Developing an Integration Events.

  1. Definition of Publisher.
  2. Deciding Parameters of Publisher.
  3. Invoking the Publisher.

Let's Understand this with an Example.
Suppose Customer Require an action in the Expense Page to Show List of G/L Account Where Expense Code is Used and same time we should be updating G/L Account when an Expense in deleted.

Let's Add two Function in Expense Table to Achieve same -
CheckExpenseUsed & UpdateRelatedGLAccounts.


Now let's suppose I am a developer decide that we want other developers to hook his/her custom code in these two functions then I will define two Publisher.

Defination of Publisher - Add two functions - OnBeforeOpenExpenseRelatedPage & OnBeforeUpdateExpenseInGLAccount



Now let's work toward the second part. The Parameters of the Integration Event are decided by developers and You need to think about what parameters will be required for the other developer for a change.

Deciding Parameters of Publisher - In these two publisher scenarios, I would like another developer to apply other filters in G/L Account variable before actual processing occur so we will add G/L Account table as variable to these publishers as Passed as Reference.



** You cannot add any code in the Function which is an Integration Event.

Last but not least we need to decide where we Invoke the Publisher in our code.
Invoking the Publisher - Let's add calling these Integration events in our code, as shown below.


During Developing these publishers, We saw that there was an option in property EventType. There were two options Integration or Business.

A Business Event is same as Integration Event with a promise - 
Business Event 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.

Now let's quickly see how the last part Subscribing an Integration/Business Event works.

Where we can Subscribe Integration/Business Events?
You can only Subscribe Integration/Business Events in the Code that you own.

  • Microsoft has already and will keep on Subscribe Integration/Business Events in Base NAV / AL Objects.
  • Addon / Solution ISV can only add Subscribers for Integration/Business Events in Addon Range Objects. They are not allowed to add in Base NAV / AL Objects.
  • Microsoft Partners can only add Subscribers for Integration/Business Events in Custom Object Range (50000..99999). They are not allowed to add in Base NAV / AL or Addon Base NAV / AL Objects. 

What Objects can be used for Subscribing Integration/Business Events?
Only Codeunit are allowed for Subscribing Published Events.

How can we Subscribe Integration/Business Events?

Three Parts for Subscribing a Published Integration/Business Events.

  1. Create a New Function.
  2. Define it as Subscriber & Select Published Event.
  3. Write Custom Code that is required.

Let's try to subscribe that we published earlier in this article.
** This part is not the part of the solution that we are building it is just sample code.

Create a new codeunit and then Create a New Function - DeleteExpenseWithAdditionalCheck and then Define it as a Subscriber.



Next, we need to tell Where is Published Event with Following Details -

  1. EventPublisherObject - Object Type and Id where Event is Published.
  2. EventFunction - Published Event Name that we want to subscribe.


** Right now are only looking for Integration / Business Events. Don't worry about Trigger Event that you see, we will discuss in future articles.

Let's work on the last part - Write Custom Code that is required.
Suppose Developer only want to remove Expense code from G/L Account only if G/L Account is Blocked then he/she can add the following line in subscriber as shown below.



Hope it makes sense and now you know about Integration / Business Events.

Next article, we will discuss What if Integration Event Does not Exist or How to do Futuristic Development in Pre-NAV 2016 Database.

Stay Tuned for More!.

Regards,
Saurav Dhyani
www.sauravdhyani.com

Comments

  1. Very Helpful and easy to understand

    ReplyDelete
  2. Easy to follow, understanding it is another ball game. Thanks for this series

    ReplyDelete
    Replies
    1. Thanks @ibrahim for the comment. Its always great to hear that people understand from these articles.

      Delete
  3. thank you for explaining in easy way

    ReplyDelete
  4. Why we call integration event and after then called subscriber event. it is like that calling function. so why we can not direct call a function apart from making an event publisher. please clear if there it is..

    ReplyDelete
    Replies
    1. Integration Events are published by the product / Service Owner not by developers.
      Microsoft adds Integration events in base product and Addon partners adds integration events in there respective ISV's.
      We as developers can only publish integration events on our add-ons or solution that we are building.

      Reason behind integration events -
      No other developer who need to modify functionality will not touch your code. In case of Microsoft events no one will modify the Microsoft base code and same applies for ISV Solution providers.

      ** Above is a situation Where we are building an module per say and once published as extension in future no one can modify base code that i have written. But to provide flexibility to other developers we have provided two Events which they can use if they need to modify standard behaviour (Standard means that was build by developer in app/extension).

      Hope it make sense.

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

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 -