microsoft / ALAppExtensions

Repository for collaboration on Microsoft AL application add-on and localization extensions for Microsoft Dynamics 365 Business Central.
MIT License
748 stars 600 forks source link

[Extensibility Bug] Extending Application Areas #19758

Open pri-kise opened 1 year ago

pri-kise commented 1 year ago

The procedure GetApplicationAreas in codeunit 9177 "Application Area Cache" does only remove spaces from the fieldref name. We have used - in our comined prefix, which leads to errors when the plattform procedure ApplicationArea is called.

Maybe all other special characters should be removed too. And you should maybe improve the documentaiton, too. https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-extending-application-areas#adding-an-application-area

[Scope('OnPrem')]
procedure SetupApplicationArea()
begin
    ApplicationArea(GetApplicationAreas());
end;
local procedure GetApplicationAreas(ApplicationAreaSetup: Record "Application Area Setup") ApplicationAreas: Text
var
    RecRef: RecordRef;
    FieldRef: FieldRef;
    FieldIndex: Integer;
begin
    RecRef.GetTable(ApplicationAreaSetup);

    // Index 1 to 3 are used for the Primary Key fields, we need to skip these fields
    for FieldIndex := 4 to RecRef.FieldCount do begin
        FieldRef := RecRef.FieldIndex(FieldIndex);
        if FieldRef.Value() then
            if ApplicationAreas = '' then
                ApplicationAreas := '#' + DelChr(FieldRef.Name)
            else
                ApplicationAreas := ApplicationAreas + ',#' + DelChr(FieldRef.Name);
    end;
end;

Internal Work Item: AB#445142

pri-kise commented 1 year ago

I checked the documenation again and found some note, that only alphanumeric characters are allowed for the ApplicationArea property. https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/properties/devenv-applicationarea-property#property-values

Therefore anything else should be removed from the field name: https://github.com/StefanMaron/MSDyn365BC.Code.History/blob/ea65f641b8cd8455536977e9218cc6f56c09cabd/BaseApp/Source/Base%20Application/ApplicationAreaCache.Codeunit.al#L99

JesperSchulz commented 2 months ago

Hi @pri-kise,

we're trying to get our backlog under control, and this issue didn't make the cut. Do you consider this an important fix? In that case, I could fight for this bug to remain opened. It's 2 years old and it's not something we've heard about except in this issue. What do you think?

pri-kise commented 2 months ago

Hi @JesperSchulz, I've reported this because this can lead to a RunTime Bug that makes the Client unusable. Because you'll receive a web client Bug and the client crashes.

Since this does not seem to be on the priority list to prevent RunTime Crashes, I now have created the following idea.

https://experience.dynamics.com/ideas/idea/?ideaid=162ca15c-c702-ef11-a73c-6045bdb93e93

Maybe I'll have some spare time to get this fixed in the BaseApp Pilot.

In my opinion this is an importaned fix. Alterantively the Plattfrom Team could improve their ApplicationArea handling and support more Characters.

JesperSchulz commented 2 months ago

Runtime crashes should be on the short-list (at least if it's a likely scenario). I'll try to repro. Depending on my findings, I will reactivate the bug. I guess it shouldn't be an idea - that just doesn't seem right 😉

pri-kise commented 2 months ago

@JesperSchulz here is a small repro: https://github.com/pri-kise/msdyn365bc-application-area-test

  1. Make sure you have an environment where ApplicationArea is enabled (In OnPrem Docker Open Company Information and switch experience tier)
  2. Open PTE Setup Page and Enable "Feature A"
  3. Close your Browser Tab
  4. Open a new Tab (new Session)
  5. The Client will crash now (see output below)
Could not open the company.

While opening company 'CRONUS AG', the following error occured: ''#Basic,#Suite,#RelationshipMgmt,#Jobs,#FixedAssets,#Location,#BasicHR,#Assembly,#ItemCharges,#Warehouse,#Service,#Manufacturing,#Planning,#Dimensions,#ItemTracking,#Intercompany,#SalesReturnOrder,#PurchReturnOrder,#Prepayments,#CostAccounting,#SalesBudget,#PurchaseBudget,#ItemBudget,#SalesAnalysis,#PurchaseAnalysis,#InventoryAnalysis,#Reservation,#OrderPromising,#ADCS,#Comments,#RecordLinks,#Notes,#VAT,#ItemReferences,#BasicEU,#BasicDE,#PTE-XXXFeatureA' is not a valid value for the APPLICATIONAREA function parameter.

The value must be a text string that contains one or more application area tags.
A tag must start with # and can be followed by any combination of letters (Aa-Zz) and numbers (0-9).
Use a comma to separate multiple tags. Example: #Basic,#Suite'

AL stack trace:
"Application Area Mgmt."(CodeUnit 9178).SetupApplicationArea line 2 - Base Application by Microsoft
"Application Area Mgmt. Facade"(CodeUnit 9179).SetupApplicationArea line 4 - Base Application by Microsoft
LogInManagement(CodeUnit 40).LogInStart line 43 - Base Application by Microsoft
LogInManagement(CodeUnit 40).CompanyOpen line 10 - Base Application by Microsoft
LogInManagement(CodeUnit 40).OnCompanyOpen line 2 - Base Application by Microsoft
"System Initialization"(CodeUnit 150).OnAfterInitialization(Event) line 2 - System Application by Microsoft
"System Initialization Impl."(CodeUnit 151).Init line 18 - System Application by Microsoft
"Company Triggers"(CodeUnit 2000000003).OnCompanyOpen(Event) line 2

image