Replacing OnBeforeCompanyOpen and OnAfterCompanyOpen

To improve the login time for Dynamics 365 Business Central, extensions should no longer use the OnBeforeCompanyOpen and OnAfterCompanyOpen events. Following are some recommended patterns to use in place of these events.

  • Move the code to the actual usage of the extension.

  • Code written on the subscribers that are called from these triggers must be safe. Every GET, MODIFY, DELETE, and INSERT operation must be written with IF THEN, to avoid raising conditions that could prevent user from signing in.

  • The code should start with check IF NOT GUIALLOWED THEN EXIT; to avoid impacting Web services code. Other checks to exit early should be added to the beginning of the code so that login performance is not affected.

  • If the extension is subscribing to OnBeforeCompanyOpen or OnAfterCompanyOpen in order to perform some long-running data update, then either call Update when the extension gets called in code for the first time or apply the new task scheduler pattern for Update 6 and later. This applies to code that is not crucial.

    // Add 15s
  • If you are inserting data for a newly created company, we recommend subscribing to OnCompanyInitialize from Codeunit 2 instead. Use Installation or Upgrade code for the extension, or to set up on the first usage and if this is not possible only then it should be OnCompanyInitialize be used to populate data for new companies. This runs after every upgrade.

See Also

Checklist for Submitting Your App
Rules and Guidelines for AL Code