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.

Saurav Dhyani


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

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.

NAV 2013 Upgrade Part III - Data Upgrading.

Hi all, As per agenda we need to discuss the data upgrade in NAV 2013. The process is similar to what used to be till NAV 2009 R2 but with some changes. Let's start the process. Remember -  1) You can only upgrade a database to NAV 2013 from NAV 2009 SP1 / R2 SQL Only. 2) The Synchronization of users with SQL Server is no more required.