Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

Better understanding of Event Subscribers, Integration Events and IsHandled flags

(0) ShareShare
ReportReport
Posted on by 249

Hi,

I'd like to have a better understanding of event subscribers, integration events and IsHandled flag. Let's say there is a procedure in a base codeunit that looks like:

local procedure Procedure1()

    var
        IsHandled: Boolean;
    begin
        IsHandled := false;
        FirstIntegrationEvent(IsHandled);
        if IsHandled then
            exit;

        code
        SecondIntegrationEvent();
    end;
In my own codeunit, I create an event subscriber to the FirstIntegrationEvent, where I modify the code section and set IsHandled to true so the base code doesn't get executed
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Codeunit", 'FirstIntegrationEvent', '', true, true)]
    local procedure "Codeunit1_FirstIntegrationEvent"
    (
        var IsHandled: Boolean
    )
begin
        baseCodeModified
        //SecondIntegrationEvent(var1); //This line is removed as I can't called the 2nd integration event from my event subscriber
        IsHandled := true;
end;
I'm assuming, since I'm using IsHandled, that the 2nd integration event will never be called, correct? I know I could add some code to handle it if I need to call that 2nd event trigger. But what if another app/extension is calling that 2nd integration event. That part of the code from that extension will just be ignored?
It makes no sense to me, what am I missing
  • Suggested answer
    Greg Enns Profile Picture
    Greg Enns 1,102 on at
    RE: Better understanding of Event Subscribers, Integration Events and IsHandled flags

    You are correct. If you set IsHandled = TRUE, then the SecondIntegrationEvent will not be called. This is the difficulty and danger of customization.

    Your options are:

    A. You are responsible for making sure everything that needs to happen happens in your EventSubscriber.

    B. Handle ALL code in your Subscriber procedure.

    C. Subscribe to a different IntegrationEvent

    As you said, option B is difficult because you don't know who/what else might be subscribed to the SecondIntegrationEvent.

    Option C is always worth exploring. Perhaps you can find an IntegrationEvent later in the process? You might have to "Undo" some of what was done after FirstIntegrationEvent but that can still be the better option at times. Keep in mind that you can ask Microsoft to add IntegrationEvents (aka. "Event Publisher") anywhere in the system. You can do that here: AL Event Requests

  • Suggested answer
    Marco Mels Profile Picture
    Marco Mels on at
    RE: Better understanding of Event Subscribers, Integration Events and IsHandled flags

    Hello,

    We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist. If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    dynamicsuser.net/.../developers

    I will open this up to the community in case they have something to add.

    Thanks.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,387 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans