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.
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.
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.
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.
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 -
** 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
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.
- Definition of Publisher.
- Deciding Parameters of Publisher.
- 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.
- Create a New Function.
- Define it as Subscriber & Select Published Event.
- 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 -
- EventPublisherObject - Object Type and Id where Event is Published.
- 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
Very Helpful and easy to understand
ReplyDeleteGreat to hear that you like it.
DeleteEasy to follow, understanding it is another ball game. Thanks for this series
ReplyDeleteThanks @ibrahim for the comment. Its always great to hear that people understand from these articles.
Deletethank you for explaining in easy way
ReplyDeleteWelcome @Abhishek Yadv.
DeleteWhy 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..
ReplyDeleteIntegration Events are published by the product / Service Owner not by developers.
DeleteMicrosoft 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.