Skip to main content
Dynamics 365

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