How to test your event subscriptions

Many developers have started using the events that are raised in Dynamics NAV, and some have even started adding events to their solutions. There is some concern that a subscription will break if the interface of an event is changed. As a developer, you can verify that the subscription is active by running page 9510, Event Subscriptions.

When I work with a subscription, I often apply the following code to extend the Event Subscriptions page.

I start by adding the table.


Then, on the Event Subscriptions page, I add the following action.


Lastly, I add three lines at the end of the OnAfterGetRecord function:


Now, I can toggle a Gate Me flag on the page.

Normally, I would like a wake-up call when I start the client in case I introduced a breaking change. I do this by creating a subscriber to the OnAfterCompanyOpen event.


And yes, I do get this error from time to time.

How to write tests for event subscriptions

It is very simple to write a unit test for a subscription that has been added.


And by running the test tools, the test can be run like any other test.


Best regards,

Anders Larsen

Senior Engineering Lead, Dynamics NAV Application Team

Comments (5)

  1. Alejandro says:

    As soon as events functionality appears, at my Company we started to use it but, soon we detect the “issue” you mention. We were not able to reproduce the error of events stop working and so, we stopped using them at all. Could we expect a hotfix to solve this error? What do you mean with “the interface of an event”? Thank you.

    1. Anders says:

      Thanks for asking.
      Please run page 9510 – Event Subscription where there is a column Error Information that may help you with the concrete error.
      When is wrote “the interface of an event” I was referring to parameter names and type.

      1. Alejandro says:


        We have just detected a new issue, having and event declared on the OnAfterIntert in the table 18, it stopped working today without having modified anything related to it, and worst, at the 9510 page it appears as Active without any error. Compiling the Subscriber codeunit fixed it.

        — Alejandro —

        1. Kenneth Fuglsang says:

          I have seen this issue a number of times as well – on many different builds of NAV2016.

          It seems to stop working when the publishing object is modified (e.g. by importing a fob). It does not seem to matter what the actual change is. As you mention Alejandro, 1) the subscription is still active in the “Event Subscription” page, and 2) a recompile of the subscribing object fixes the issue.

          1. Pallea says:

            @Kenneth – Exactly thati is the correct procedure. It has been mentioned several times on various forums and yammer that this is the correct solution: Recompile the subscribing object – or even better all objects if it does not fix the problem at first attempt.


Skip to main content