Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discussion: Introduce company initialize in System Application #2317

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AndreasMoth
Copy link
Contributor

@AndreasMoth AndreasMoth commented Nov 5, 2024

I have created this PR to start a discussion of whether we should have company initialize in System Application and see how it might look like. We currently have apps with tables that require setup data per company. So far we insert data on the fly, but should we always do this check or should it be done as part of initializing each company?
Either way, let's see.

System Application examples are: "AAD Application Setup", "Setup Azure AD Mgt. Provider", "Register Company Signal".

Copy link

github-actions bot commented Nov 5, 2024

Could not find a linked ADO work item. Please link one by using the pattern 'AB#' followed by the relevant work item number. You may use the 'Fixes' keyword to automatically resolve the work item when the pull request is merged. E.g. 'Fixes AB#1234'

}
field(3; "Initialized Version"; Code[20])
{
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I'd add here is a field: IsCompanyInitialized (or something like that)

If you look at some code in BaseApp, we are leveraging the existences of GLSetup to determine this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was using the fact that the table is empty as it not being initialized. Do you have a suggestion for when we want to insert a record but state that the company has not been initialized?

Comment on lines +26 to +28
CompanyInitializeCodeunit.InitializeCompanySetup();

CompanyInitializeCodeunit.InitializeCompany();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the gain of raising two identical events (except for their name) in a row?
And shouldn't their names start with On*?

Copy link
Contributor Author

@AndreasMoth AndreasMoth Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, they should start with On. My thought on two events is that we have a lot of setup tables that are standalone and doesn't depend on anything else being setup and then we have other tables that does depend on the initial setup tables being filled in. With this you always subscribe to the first event if you're independent of any other setup and second if you are dependent. Of course this does not account for third or fourth level dependencies and there are also many other ways to deal with this kind of problem. It's simply trying to help a very complicated problem a little bit.

CompanyInitializeCodeunit.InitializeCompany();
end;

[EventSubscriber(ObjectType::Codeunit, Codeunit::"System Initialization", 'OnAfterLogin', '', false, false)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[EventSubscriber(ObjectType::Codeunit, Codeunit::"System Initialization", 'OnAfterLogin', '', false, false)]
[EventSubscriber(ObjectType::Codeunit, Codeunit::"System Initialization", OnAfterLogin, '', false, false)]


namespace System.Environment.Configuration;

codeunit 900 "Company Initialize"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved to the platform system events. Whenever a new company is created they should trigger the initialize company event.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice opportunity to improve the flows.


fields
{
field(1; "Primary Key"; Integer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved to the company table so we track for each company.
Keep in mind that it is by design that we can run it multiple times.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why we want to run this multiple times?


if NavApp.GetCurrentModuleInfo(ModuleInfo) then
CompanyInitialize."Initialized Version" := format(ModuleInfo.AppVersion());
CompanyInitialize.Insert();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can initialize company many times, the codeunit 2 must be safe to run many times. This logic is also wrong, it should be moved after Initialize company not before. We could partially commit and keep the record.

codeunit 900 "Company Initialize"
{
[IntegrationEvent(false, false)]
internal procedure InitializeCompanySetup()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer On for the events, it increases readability

if not GuiAllowed() then
exit;

if ClientTypeManagement.GetCurrentClientType() = ClientType::Background then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most important check that needs to be refactored is the check that we have on the GLSetup.Get(). We should introduce concepts of force initialization and a better check if it was implemented or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants