Dynamics NAV and … itself

So why would you want to integrate Dynamics NAV with itself? Well, for starters, the simple fact that page parts have a really difficult time talking to one another is a pretty good place to start.  In this tutorial we are going to go over how to get two different page parts that are on the same master to interact with one another. This will involve using some C# .NET magic.

Here is the basic setup. We are going to create a C# object on the master page, and have the master page listen for any events that the object might fire. We are then going to pass the object to each of the sub pages we want to talk to. Next, we will setup the calling triggers on each sub page. And finally, set up the listener on the master page. With this setup, you could add as many sub pages as you like without adding much code. We use the master page to handle all events since it as access to each of the sub pages.

So lets begin.

First we will make our C# add in. This addin is very simple. We are going to give it a payload, and an event number. This way we know what sub page is calling the event if there are similar pages.

This is going to be our Event Args, again, just a payload and event number. You can always add in more things, but this way it stays generic and reusable.

This is the PageEvent class. There is not a whole lot here. We just need a way to fire the event and then to listen for it passing in our PageEventArgs. That’s all.

With the C# out of the way we can now begin to write the C/AL portion.

Sub Pages:

On each of the sub pages we need to setup a global PageEvent variable. And a way to set this variable from the master page. Create the following variable and function on each sub page. While you are on the sub pages, you can add in the firing code. This is a single line that uses the PageEvent. Most likely this function will be called in the OnAfterGetCurrRecord  trigger. Simply pass in your payload, usually an id or someway to identify a record, and an event number. The event number is so you know on the master page who fired this event.

PageEventdotnetRyan.Erb.Blog.Demo.PageEvent.'Ryan.Erb.Blog.Demo, Version=, Culture=neutral, PublicKeyToken=null'

SubPage Code

Master Page:

The master page is a bit different. We again want to add a global PageEvent variable, but make sure that you turn on “With Events”. This will create the call back function for when ever our sub pages make a call to FireEvent() . In the OnOpenPage  trigger we want to instantiate our PageEvent variable. Also, we want to pass it to each sub page by calling our SetPageEvent()  we made earlier. The only thing left to do is add in the code to handle your events. This usually involves setting an active record or calling and passing info to a different sub page.


You are done!

Now your sub pages can happily talk to one another and pass back info without an issue. The C# add-in you made can easily be used with other pages if you follow the same pattern.

Hope this helps in your NAV adventures!

Leave a Comment