From 582e46a46a2e7f067c3797703bfb2064368ea3cf Mon Sep 17 00:00:00 2001 From: Andreas Moth Date: Tue, 5 Nov 2024 10:57:50 +0100 Subject: [PATCH] Introduce company initialize in System Application --- .../CompanyInitialize.Codeunit.al | 19 +++++++ .../CompanyInitialize.Table.al | 33 ++++++++++++ .../CompanyInitializeImpl.Codeunit.al | 51 +++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 src/System Application/App/Company Initialize/CompanyInitialize.Codeunit.al create mode 100644 src/System Application/App/Company Initialize/CompanyInitialize.Table.al create mode 100644 src/System Application/App/Company Initialize/CompanyInitializeImpl.Codeunit.al diff --git a/src/System Application/App/Company Initialize/CompanyInitialize.Codeunit.al b/src/System Application/App/Company Initialize/CompanyInitialize.Codeunit.al new file mode 100644 index 0000000000..d5aca604da --- /dev/null +++ b/src/System Application/App/Company Initialize/CompanyInitialize.Codeunit.al @@ -0,0 +1,19 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ + +namespace System.Environment.Configuration; + +codeunit 900 "Company Initialize" +{ + [IntegrationEvent(false, false)] + internal procedure InitializeCompanySetup() + begin + end; + + [IntegrationEvent(false, false)] + internal procedure InitializeCompany() + begin + end; +} \ No newline at end of file diff --git a/src/System Application/App/Company Initialize/CompanyInitialize.Table.al b/src/System Application/App/Company Initialize/CompanyInitialize.Table.al new file mode 100644 index 0000000000..309d070d59 --- /dev/null +++ b/src/System Application/App/Company Initialize/CompanyInitialize.Table.al @@ -0,0 +1,33 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ + +namespace System.Environment.Configuration; + +table 900 "Company Initialize" +{ + DataClassification = SystemMetadata; + + fields + { + field(1; "Primary Key"; Integer) + { + } + field(2; "Initialized Time"; DateTime) + { + } + field(3; "Initialized Version"; Code[20]) + { + } + } + + keys + { + key(Key1; "Primary Key") + { + Clustered = true; + } + } + +} \ No newline at end of file diff --git a/src/System Application/App/Company Initialize/CompanyInitializeImpl.Codeunit.al b/src/System Application/App/Company Initialize/CompanyInitializeImpl.Codeunit.al new file mode 100644 index 0000000000..dca84fd67e --- /dev/null +++ b/src/System Application/App/Company Initialize/CompanyInitializeImpl.Codeunit.al @@ -0,0 +1,51 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ + +namespace System.Environment.Configuration; + +using System.Environment; + +codeunit 901 "Company Initialize Impl." +{ + Access = Internal; + + procedure InitializeCompany() + var + CompanyInitialize: Record "Company Initialize"; + CompanyInitializeCodeunit: Codeunit "Company Initialize"; + ModuleInfo: ModuleInfo; + begin + CompanyInitialize."Initialized Time" := CurrentDateTime(); + + if NavApp.GetCurrentModuleInfo(ModuleInfo) then + CompanyInitialize."Initialized Version" := format(ModuleInfo.AppVersion()); + CompanyInitialize.Insert(); + + CompanyInitializeCodeunit.InitializeCompanySetup(); + + CompanyInitializeCodeunit.InitializeCompany(); + end; + + [EventSubscriber(ObjectType::Codeunit, Codeunit::"System Initialization", 'OnAfterLogin', '', false, false)] + local procedure OnLoginInitializeCompany() + var + CompanyInitialize: Record "Company Initialize"; + ClientTypeManagement: Codeunit "Client Type Management"; + begin + if not GuiAllowed() then + exit; + + if ClientTypeManagement.GetCurrentClientType() = ClientType::Background then + exit; + + if GetExecutionContext() <> ExecutionContext::Normal then + exit; + + if CompanyInitialize.Get() then + exit; + + InitializeCompany(); + end; +} \ No newline at end of file