Skip to main content

Microsoft Dynamics NAV 2016 - Events What Else We Need to Know.

Hi All,

Recap Of What we Discussed In The Series "We Have seen how to use the Database Trigger, Business and Integration Events." 

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

Let's See What Else we Need to Know about Events.



Point / Question 1 - Do I Need to Add All Events I want or There are Some Standard Events From Microsoft?

There are so many Events Published By Microsoft in Microsoft Dynamics NAV 2016, but not all are subscribed. Any Event which is Not Subscribed is a Kind of Function which is not called anywhere?

Microsoft have Placed so many Such Events in the Business Area where they Feel the we partners Customize it Most. Let's see one of them.

Design Codeunit 90 and Navigate to End, You will See Three Events Which are Integration and Can be Used Whenever you want -
> OnBeforePostPurchaseDoc
> OnBeforePostCommitPurchaseDoc
> OnAfterPostPurchaseDoc

Just Search for them you will also see the Publisher in the same Object.


If you are looking for all the events published by Microsoft, Here is the List on MSDN.

Point / Question 2 - How can I Check which all Active Events in System and how you say that above Purchase Post Events are Not Called?

With Microsoft Dynamics NAV 2016, Suppose if you are working for a project for First Time and you don't know which all events have been customized AND Subscribed too.

Why we need to know that?
Because we don't want to rewrite the Same thing again and again, if some of our colleague have done it.From the Developer Environment, Tools Menu select Debugger and Event Subscriptions. All Events you see here as below are defined, published & Subscribed.


Point / Question 3 - Is it Mandatory to Make an Event Publisher as Local?

Thanks +Peter D. Jørgensen for suggesting the Issue in this point.

No, As we all know that Local Functions can Only be triggered within object Only.

As we discussed about Integration Events related to Codeunit 90., all those we local so that means they can only be triggered within the Codeunit 90.

So if want to subscribe trigger the function Outside we will not make them local.

A Best example to Look is The Same Function (OnAfterPostPurchaseDoc) is also there in Table 38 (Purchase Header) which can be triggered by other objects too, as its a global one.



Point / Question 4 - Can I Write Code While Publishing Event?

NO, we can only use Documentation starting with // on the Publisher Function.

Point / Question 5 - Where all can I Subscribe and Publish Events?

Table, Page, Report,Codeunit & XmlPort -Can Publish Events.
Codeunits                                              -Can only Subscribe the Events. All Other Objects Cannot.
Query & Menu suits                               -Cannot Subscriber and Cannot Publish Events.

Point / Question 6 - How can I De-activate a Published Event?
Just Delete all the subscribers to the Published Event, Then the Published Event will be Deactivated.

Post / Question 7 - Remember When we write custom Code?
Whenever you write a custom code, remember that always use validate for every field because there may be database triggers which on get executed when OnValidate Trigger or on table trigger.

So Any-time we write a Custom Code We need to Validate all fields, that we want to assign.

Point / Question 8 - Which Subscriber Get Priority if there are multiple subscriber, for same event doing different thing on same data?

Here is What Microsoft Says -
"There can be multiple subscribers to the same event from various locations in the application code. When an event is raised, the subscriber functions are run one at a time in random order. You cannot specify the order in which the subscriber functions are called."

As we Know that we can only Subscribe Using Codeunit, so here is the Pattern That I Can Identify till now, may be I am Wrong=>

 > Priority First Based on the Object No, on which the Event is Subscribed.
 Priority Secondly Based on The Function Position (if there are multiple subscribers to Same Event in Same Object).

So if I have Two Codeunit which subscribe same Trigger Events in Following Order -

 > Codeunit 60003.
> Subscriber 5
> Subscriber 2
> Subscriber 3
> Subscriber 4

 > Codeunit 60004.
> Subscriber 1

So the calling will follow Below Pattern -
> Subscriber 5 > Subscriber 2 > Subscriber 3 >Subscriber 4 > Subscriber 1

** No Guarantee, on above points its just my findings.

Hope I am able to answer most of the queries. If you have any other queries, please post it a Question to me Via Contact me Page on the Top or Put a Comment to Article.

Your Feeback (as comment) on the article are most welcome.

Stay Connected.

Regards,
Saurav Dhyani
saurav-nav.blogspot.com

Comments

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.