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.

navblog_events1

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

navblog_events2

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

navblog_events3

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.

navblog_events4

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.

navblog_events5

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

navblog_events7

Best regards,

Anders Larsen

Senior Engineering Lead, Dynamics NAV Application Team

Comments (2)

  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.
      /A

Skip to main content