How to Set Up a Manual Event Subscriber in Business Central

by | Updated January 7, 2021 | Dynamics 365 Business Central

An event subscriber is an AL method that listens to a specific event and determines which action to take when that event is raised.

Sometimes you need to subscribe to an event, but you need to control when that method code must be run. This can be done using the EventSubscriberInstance property as Manual.

In this way, you can determine when to activate your event subscriber methods.

When using the manual event subscriber, you will need to bind and unbind the subscriber codeunit.

The codeunit instance binds to the same exact instance and events will be raised on this instance.

If you define your subscriber codeunit as a local variable, once it goes out of scope, all the bindings are removed and you will not need to unbind it.

Let’s explain it with a practical example:

Setting up a Manual Event Subscriber | Example

Say you were asked to use an additional vendor remittance address for the check instead of the standard address.

These new fields were added to the vendor table and the vendor card page.

Now, you need to subscribe to the correct event in order to use the additional remittance address instead of the standard one.

If you check the code, you realize that there is an event to which you can subscribe and successfully place your code.

Notice that the variable Handled will determine if the standard code is executed or not.

The issue here is that this same function is called from many other reports and functionalities and all of them will be affected by it. Since that’s not what you want, you’ll need to manually subscribe the instance, setting the property EventSubscriberInstace = Manual.

Now, in the customized Check code, you bind/unbind the codeunit at the correct moment.

Let’s check the results.

If the check configured is a standard one, the new code should not be executed.

When printing the check, the standard address is shown as expected.

If the customized check is configured, the new code must execute.

When printing the check, the additional remittance address is shown as expected.

Related Posts

0 Comments

Submit a Comment

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

Upcoming Events

january

14jan11:00 am12:00 pmConfab with Stoneridge - Livestream - Looking Forward: Predictions for Technology in 2021

20jan10:00 am10:30 amThe Modern Manufacturer - Demand Forecasting Functionality

27jan12:00 pm12:45 pmFour Keys to Choosing the Best ERP or CRM Solution: Part 1 – Fit

28jan11:00 am12:00 pmConfab with Stoneridge - Livestream - Ask the Experts!

february

03feb10:00 am10:30 amThe Modern Manufacturer - Enterprise Asset Management

03feb12:00 pm12:45 pmFour Keys to Choosing the Best ERP or CRM Solution: Part 2 – Platform

10feb12:00 pm12:45 pmFour Keys to Choosing the Best ERP or CRM Solution: Part 3 – Implementation Partner

11feb11:00 am12:00 pmConfab with Stoneridge - Livestream - Live Agents, Power Virtual Agents, Omnichannel – Oh My!

16feb12:00 pm12:45 pmFour Keys to Choosing the Best ERP or CRM Solution: Part 4 – Cost

17feb10:00 am10:30 amThe Modern Manufacturer - Machine Maintenance Work Orders

25feb11:00 am12:00 pmConfab with Stoneridge - Livestream - Surfing Through the Dynamics 365 Wave 1 2021 Release

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