Add System-Initialization Sub to Install Codeunit #203
Replies: 3 comments 5 replies
-
One additional thing to mention here is the Retention Policy. Maybe even a new Best Practice to always allow the selected tables for the retention policy on newly created companies. |
Beta Was this translation helpful? Give feedback.
-
Looks like Microsoft adopted this rule/guideline in AA0235: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/analyzers/codecop-aa0235 I cannot get it to trigger yet though (do you?), might be a bug, ... or I am forgetting something right now. 🤔 |
Beta Was this translation helpful? Give feedback.
-
Does anybody know what's the difference between the events [EventSubscriber(ObjectType::Codeunit, Codeunit::"System Initialization", 'OnAfterInitialization', '', false, false)]
local procedure AddAllowedTablesOnAfterSystemInitialization()
begin
AddRetentionPolicyAllowedTables();
end; And the event [EventSubscriber(ObjectType::Codeunit, Codeunit::"Company-Initialize", 'OnCompanyInitialize', '', false, false)]
local procedure InitializeCompany()
begin
InitializeModuleSetup();
end; |
Beta Was this translation helpful? Give feedback.
-
Hello there,
there's nothing wrong with initializing your setup tables (in all/certain companies) when your app gets installed (
SubType = Install
) and you should keep on doing that.What I would suggest: make sure that these functions are called whenever there is a new company being created (aka. "System-Initialization" / OnCompanyInitialize)
Therefor:
Bad code
Good code
Beta Was this translation helpful? Give feedback.
All reactions