Warning: number_format() expects parameter 1 to be float, string given in /data/web/virtuals/7298/virtual/www/domains/kepty.cz/wp-includes/functions.php on line 423

Isolated events

by May 17, 2022AL Language

Home 9 Development 9 AL Language 9 Isolated events ( Page )

With Business Central 2022 wave 1, a new setting for event publishers was introduced. Until this version, any error in any event subscriber caused interruption to the current running process and stopped the whole activity. In some cases (such as log-in), this is definitely unintended.

For this reason, Microsoft introduced Isolated Event Publishers. These events work the same as Codeunit.Run(..) – each call is executed in its own transaction, all errors are trapped, and only the event subscriber that caused the error is rollbacked.

To define a publisher as an Isolated Event, a new optional parameter was added to the publisher definition (see the image below).

Example

Let’s start with creating a new event publisher (nonIsolated – the third parameter in IntegrationEvent() is set to FALSE).

    internal procedure RaiseIsolatedEvent()
    begin
        OnSomething();
    end;

    [IntegrationEvent(false, false, false)]
    local procedure OnSomething()
    begin
    end;

And also create two event subscribers for our event.


    [EventSubscriber(ObjectType::Codeunit, Codeunit::"TST W1 Isolated Events", 'OnSomething', '', false, false)]
    local procedure FirstSubscriber()
    begin
        Message('Calling the first subscriber.');

        if true then
            Error('Error in the first subscriber.');
        Message('End of the first subscriber.');
    end;

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"TST W1 Isolated Events", 'OnSomething', '', false, false)]
    local procedure SecondSubscriber()
    begin
        Message('Calling the second subscriber;');
        if true then
            Error('Error in the second subscriber.');
        Message('End of the second subscriber.');
    end;

If you raise the event, only one of the subscribers is called – one message followed by an error message is shown.

Now let’s change the third parameter of IntegrationEvent(..) to true (to define the event as Isolated).

    [IntegrationEvent(false, false, true)]
    local procedure OnSomething()
    begin
    end;

If you raise the event once again, the behaviour is entirely different. Two messages without any error are shown, meaning no interruption to any running processing!

Conclusion

This new configuration for event publishers is an excellent way to manage external integration better. As a developer of an ISV solution or any solution extended by a third-party company, you may want to manage whether extensions can interrupt your processes (or define only specific events where error can happen).

Even more, with the combination of ClearLastError() and GetLastErrorText(), you can manage the errors in your processes much more easily – just clear the error before the event is called and check whether any error happened after all subscribers finished.

On the other hand, it also adds more complexity to the design of your solution. You should not make all your events Isolated (to be more specific, you should make the event Isolated ONLY if you really know the impact of this change), as after that, extending the application can not stop code from the executing!

Recent Articles from the category

Collectible Errors?! Is it already in use?

Collectible Errors?! Is it already in use?

Collectible Errors?! Is it already in use? This is the second part of my new article series about Collectible Errors. Let's check out the first part here: Collectible Errors?! | Microsoft Dynamics 365 - Ing. Tomáš Kapitán (kepty.cz) or you might be interested in my...

read more
Collectible Errors?!

Collectible Errors?!

Collectible Errors?! It has been already almost a year since ErrorInfo datatype & CollectibleErrors were introduced (I already have an article about basic structure: ErrorInfo data type & Collectible Errors). This article was released for the first time in...

read more
Substituting standard reports

Substituting standard reports

Report objects cannot be extended in versions previous to the Business Central 2021 release wave 1 version when ReportExtensions object was introduced. Since then, many of changes we need to do in reports can be done without creating a new copy of object. On the other...

read more
Custom Filter Tokens

Custom Filter Tokens

As a user of the Business Central you have some constants you can use to filter or insert values. These constants contain useful values for data manipulation such as t / today for date field - return current dateq / quarter for date field filters - return range of the...

read more
1D & 2D Barcodes in Business Central 19.1

1D & 2D Barcodes in Business Central 19.1

Business Central (cloud-only!) includes one-dimensional (1D) barcode fonts since Microsoft Dynamics 365 Business Central 2020 wave 2 (17.0) was released in October 2020. It is a great improvement to how developers can handle requirements from their clients to print...

read more
How to let users choose field(s) properly

How to let users choose field(s) properly

When some complex functionality is developed, it is sometimes necessary to let users choose a specific field. This can be required for field permissions, mapping imported values or any similar process. Earlier, the usual way was to create a link on the Field table...

read more
Working with Translation Files (XLIFF)

Working with Translation Files (XLIFF)

How does the translation file work? In Microsoft Dynamic 365 Business Central, displaying different languages is done using the XLIFF files extension (.xlf). The generated XLIFF files have strings that are specified in properties like Captions, Tooltips......

read more
ErrorInfo data type & Collectible Errors

ErrorInfo data type & Collectible Errors

A major change to AL Language development is here! Collectible errors can hugely improve any validation procedures. And what's new? Everything is about a new data type ErrorInfo. ErrorInfo data type ErrorInfo is a new data type introduced in Microsoft Dynamics 365...

read more

Sign Up for News

Certifications

Highest certification
Microsoft Data Management and
also in D365 Business Central

Microsoft Certified: Dynamics 365 Business Central Functional Consultant Associate

See other certifications here