How to Place Custom Code Using Events in Microsoft Dynamics NAV 2016

by | Apr 4, 2019 | Development, Dynamics NAV

With every modification to Microsoft Dynamics NAV we are faced with the tough question, where should I place this new code? Do we place it directly on the page? The action on the page? The table the page references? Or a code unit? This may seem like a minuscule decision but if your company repeatedly makes the wrong decision, you will accumulate a tremendous amount of technical debt. This causes upgrades and future modifications to substantially increase in time, difficulty and overall cost.

Avoiding altering base NAV functionality will make your upgrades faster and less painful. Microsoft has helped developers with this by introducing events in NAV 2016. Events utilize a hooking pattern that allows developers to add their modifications without touching base NAV code.

In this example, we are going to set up an Event to run after we release a sales order.

Steps:

  1. Create a custom code unit to store your events.
  2. Create your function and set the property Event to Subscriber
    1. Publisher: Allows you to create a new Event. Objects comes with stock events, however, if you need to create custom events you would set your function to Publisher.
    2. Subscriber: Is called when Events are triggered.
      • For this example, after a sales order is successfully released, our code in this newly created Event Subscriber will run.

Setting a function to Subscribe to an Event

  • Set the Event to Subscriber
  • Set the EventPublisherObject to Codeunit 414, Release Sales Document
  • Set the EventFunction to OnAfterReleaseSalesDoc

Custom Code NAV

This message will appear, click Yes. This will change your event subscriber function parameters for you.

Custom Code NAV

You can now add custom code to your new Event Subscriber function.

Custom Code NAV

Here you can see our Event Subscriber running after you click release.

Custom Code NAV

Going back to our original question, where should we place custom modification code? We recommend placing customizations in custom code units utilizing events to avoid making modifications in base NAV code. This will minimize your company’s technical debt and allow for more cost-efficient upgrades and future modifications.

If you are a Dynamics NAV user and have more questions, contact the team at Stoneridge Software for additional help.

Related Posts

  • Over the past several versions of Microsoft Dynamics NAV, we’ve seen improvements in the application’s sorting functionality. In older versions of NAV, you were limited to a pre-defined set of…

  • CONTENTS

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Upcoming Events

july

16jul11:00 am12:00 pmConfab with Stoneridge - Livestream - Business Intelligence Power Hour

22jul10:00 am10:30 amOn the Job with Dynamics 365 - Manufacturing Material Handler

22jul12:00 pm1:00 pmImprove Field Service Delivery and Increase Customer Satisfaction

30jul11:00 am12:00 pmPower Apps Power Hour

august

05aug10:00 am10:30 amOn the Job with Dynamics 365 - Manufacturing Shipping / Receiving Department

05aug12:00 pm1:00 pmHow Ag Retailers Can Simplify Processing Equity Payments using Levridge

12aug10:00 am10:30 amWhy Levridge Grain? How to Achieve Efficient and Accurate Scale Tickets

12aug12:00 pm1:00 pmThe Three Paths to Dynamics 365 Finance and Supply Chain from Dynamics AX

13aug11:00 am12:00 pmConfab with Stoneridge - Livestream - Dynamics 365 2020 Wave 2 Preview

19aug10:00 am11:00 amWhat is Levridge? An Overview of the Ultimate Ag Solution

About Stoneridge
Stoneridge Software is a unique Microsoft Gold Partner, with emphasis on partner. With specialties in Microsoft Dynamics 365, Microsoft Dynamics AX, Microsoft Dynamics NAV, Microsoft Dynamics GP and Microsoft Dynamics CRM, we focus on attracting the most knowledgeable experts in the field to our team, and prioritize delivering stellar solutions with maximum impact for your business. At Stoneridge, we are deeply committed to your results. Each engagement is met with a dedicated team, ready to provide thorough, tailored, and expert service. Based in Minnesota, we intentionally “step into your shoes,” wherever you are. We focus on what you care about, and develop trusting, long-term relationships with our clients.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!

X