topic hubAL Developmentofficial - Microsoftreviewed - checked by Opus

Restrictions

Restrictions in Business Central development best practices covers what AL code should avoid: UI in web service objects, the obsolete OnCompanyOpen event, and the deprecated OnBeforeCompanyOpen and OnAfterCompanyOpen events. It answers questions on how to avoid sign-in errors, login slowdowns and web service exceptions.

Path: Development > Rules, guidelines, and best practices > Best practices > Restrictions · tier official · system development · narrative reviewed (checked by Opus)

Overview

This section lists restrictions that developers should follow when writing extensions. One page deals with web services, where code must not show dialogs or message boxes. The other two deal with company-open and login events, which can slow or break sign-in when subscribers misbehave.

The two login pages are migration guides. One moves subscribers from the obsolete OnCompanyOpen event to the isolated OnAfterLogin event. The other gives patterns for removing OnBeforeCompanyOpen and OnAfterCompanyOpen to improve login performance.

Start with the page that matches your problem: web service UI errors, sign-in failures caused by subscriber errors, or slow login from the deprecated events.

Key points

  • Code in objects exposed as web services must not use UI elements such as dialogs, message boxes or confirmation dialogs, because they cause exceptions.
  • GuiAllowed is the related check for deciding whether UI can be shown.
  • OnCompanyOpen is obsolete; subscribers should move to the isolated OnAfterLogin event.
  • Isolated events keep subscriber errors from causing sign-in failures.
  • OnCompanyOpenCompleted is also named in the migration guidance.
  • OnBeforeCompanyOpen and OnAfterCompanyOpen are deprecated; removing them improves login performance.
  • Replacement patterns mentioned include OnCompanyInitialize and TaskScheduler.

Learn pages

Source: Microsoft Learn (CC BY 4.0). Descriptions are Learn’s own.

What Learn documents here 3 Learn pages