During trainings and/or checking different partner’s extensions code, I often see that partners adds business logic in the login process (user initializations, checking licenses and more). The custom logic in the login process is normally added subscribing to the OnAfterLoginStart event of the LogInManagement codeunit.
To all the partners I had the pleasure to speak with, I’ve always suggested a thing: if you strictly want to do that, please check to don’t raise errors inside that code, otherwise your users will be out of Business Central (you can break the sign-in process).
Starting from the new Dynamics 365 Business Central 2022 Wave 1 release (version 20), when you subscribe the above event, you have the following warning message:
Method 'OnAfterLogInStart' is marked for removal. Reason: Replaced with OnAfterLogin in codeunit "System Initialization". Tag: 20.0.AL (AL0432)
Microsoft is planning to deprecate the OnAfterLoginStart event and then you should use the new OnAfterLogin event declared in the System Initialization codeunit:
Why this change?
If you check the System Initialization codeunit, you can see that the above event is an Integration event defined as follows:
Do you see something strange?
The new Integration event definition has one parameter more:
[IntegrationEvent(false, false, true)]
What does that mean?
Starting from Dynamics 365 Business Central version 20, the Integration event definition has one more optional parameter:
IntegrationEvent(IncludeSender: Boolean, GlobalVarAccess: Boolean, [Isolated: Boolean])
You can now declared that an event is isolated, meaning that:
- Each subscriber is executed in its own transaction.
- Failures cause the transaction to be rolled back.
- Errors are trapped and execution continues.
With the new OnAfterLogin isolated event, any subscribers to this event can fail but will not block the sign-in process. An isolated event can invoke all event subscribers, even if some subscribers fail, and continue executing.
If you have critical events that can block the execution of a process, start consider using them.
Microsoft is planning to move some of the system events to a new isolated version (in V20 you will have also a new OnCompanyOpenCompleted isolated event raised during sign-in, when trying to open the company), so please always check the warnings.