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

june

02jun2:00 pm2:30 pmBusiness Intelligence for Batch Manufacturers

16jun10:00 am10:30 amHow AP automation can speed up month-end close in D365 Finance

17jun11:00 am12:00 pmConfab Live with Stoneridge – Real Time Marketing Strategies for Success

23jun10:00 am10:30 amThe Modern Manufacturer: Cost Accounting in D365

30jun10:00 am10:30 amAP Automation Checklist for a 2022 Rebound

30jun2:00 pm2:30 pmAchieving Success: How Technology Is Helping Nonprofits Thrive

july

01jul11:00 am12:00 pmConfab Live with Stoneridge – Dataverse Virtual Entities

14jul12:00 pm12:30 pmBeyond Reporting - What Business Intelligence Can Do For Your Agribusiness

15jul11:00 am12:00 pmConfab Live with Stoneridge – Integration Strategies for End User Success

21jul10:00 am10:30 amThe Modern Manufacturer: Manufacturing Software in the Real World

21jul12:00 pm1:00 pmIs it Worth it to Upgrade to Dynamics 365 Finance and Supply Chain Management? - Everything AX Users Need to Consider

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