편집

다음을 통해 공유


CodeCop Info AA0235

When using 'OnInstallAppPerCompany' you should also add 'Company-Initialize'::'OnCompanyInitialize' event subscriber.

Description

When using trigger 'OnInstallAppPerCompany' in a codeunit with 'Subtype = Install' you should also add a 'Company-Initialize'::'OnCompanyInitialize' event subscriber to ensure that new companies also have the correct setup.

Reason for the rule

'OnInstallAppPerCompany' is only run on companies that exist when installing the extension. Many extensions were missing a 'OnCompanyInitialize' subscription, so companies that were created after the extension installation were missing setup that the extension should do. For example, insertion of records in some tables was done only for existing companies and not for new ones.

Bad code example

codeunit 1160 "AP Install"
{
   Subtype = Install;

   trigger OnInstallAppPerCompany()

   begin
   ...
   end;
}

Good code example

codeunit 1160 "AP Install"
{
   Subtype = Install;

   trigger OnInstallAppPerCompany()

   begin
   ...
   end;

   [EventSubscriber(ObjectType::Codeunit, Codeunit::"Company - Initialize", 'OnCompanyInitialize', '', false, false)]
   local procedure CompanyInitialize()
   begin
   ...
   end;
}

CodeCop Analyzer
Get Started with AL
Developing Extensions