From 3b5e03c44ac0393761060af81d856fda453e18e7 Mon Sep 17 00:00:00 2001 From: Franco111000 Date: Tue, 12 May 2026 12:27:34 +0300 Subject: [PATCH 1/3] Subscription Billing: respect Default Dimension Priorities on Subscription Lines Fixes #8084. SubscriptionLine.SetDefaultDimensions becomes the single priority-aware entry point: passes SourceCodeSetup.Sales / .Purchases so Default Dimension Priority is consulted, adds Customer / Vendor as a dim source from the linked contract, and inherits the contract dim set via GetRecDefaultDimID. Mirrors the standard SalesLine.CreateDim pattern in Base App. UpdateFromCustomerContract / UpdateFromVendorContract and the other Pathway B call sites now route through SetDefaultDimensions instead of blind-merging the contract dim set as slot 2. The billing-time merge at CreateBillingDocuments.Codeunit.al lines 264 / 383 is intentionally unchanged. After this fix the Subscription Line already carries priority-resolved values, so the existing "Service Commitment wins" merge produces the correct result while preserving the original design intent that subscription line dimensions stay authoritative at billing. --- .../Tables/CustSubContractLine.Table.al | 4 +- .../CustomerSubscriptionContract.Table.al | 2 +- .../CreateSubContractLine.Codeunit.al | 4 +- .../Tables/SubscriptionLine.Table.al | 43 +++++++++++- .../Tables/VendSubContractLine.Table.al | 4 +- .../VendorSubscriptionContract.Table.al | 2 +- .../ServiceCommDimensions.Codeunit.al | 66 +++++++++++++++++++ 7 files changed, 114 insertions(+), 11 deletions(-) diff --git a/src/Apps/W1/Subscription Billing/App/Customer Contracts/Tables/CustSubContractLine.Table.al b/src/Apps/W1/Subscription Billing/App/Customer Contracts/Tables/CustSubContractLine.Table.al index 73b5e34f38..6d388e63eb 100644 --- a/src/Apps/W1/Subscription Billing/App/Customer Contracts/Tables/CustSubContractLine.Table.al +++ b/src/Apps/W1/Subscription Billing/App/Customer Contracts/Tables/CustSubContractLine.Table.al @@ -192,10 +192,10 @@ table 8062 "Cust. Sub. Contract Line" "Subscription Description" := ServiceObject.Description; ServiceCommitment.InitForServiceObject(ServiceObject, "Service Partner"::Customer); - ServiceCommitment.UpdateFromCustomerContract(CustomerContract); - ServiceCommitment."Created in Contract line" := true; ServiceCommitment."Subscription Contract No." := Rec."Subscription Contract No."; ServiceCommitment."Subscription Contract Line No." := Rec."Line No."; + ServiceCommitment.UpdateFromCustomerContract(CustomerContract); + ServiceCommitment."Created in Contract line" := true; ServiceCommitment.Insert(false); "Subscription Line Entry No." := ServiceCommitment."Entry No."; "Subscription Line Description" := ServiceCommitment.Description; diff --git a/src/Apps/W1/Subscription Billing/App/Customer Contracts/Tables/CustomerSubscriptionContract.Table.al b/src/Apps/W1/Subscription Billing/App/Customer Contracts/Tables/CustomerSubscriptionContract.Table.al index 3068c44b79..61271e7cab 100644 --- a/src/Apps/W1/Subscription Billing/App/Customer Contracts/Tables/CustomerSubscriptionContract.Table.al +++ b/src/Apps/W1/Subscription Billing/App/Customer Contracts/Tables/CustomerSubscriptionContract.Table.al @@ -2109,7 +2109,7 @@ table 8052 "Customer Subscription Contract" ServiceCommitment."Subscription Contract No." := CustomerContractLine."Subscription Contract No."; ServiceCommitment."Subscription Contract Line No." := CustomerContractLine."Line No."; - ServiceCommitment.GetCombinedDimensionSetID(ServiceCommitment."Dimension Set ID", CustomerContract."Dimension Set ID"); + ServiceCommitment.SetDefaultDimensions(true); if "Currency Code" <> ServiceCommitment."Currency Code" then begin CalculateCurrencyFactor(ServiceCommitment."Subscription Line Start Date", CustomerContract."Currency Code"); ServiceCommitment.SetCurrencyData(CurrencyFactor, CurrencyFactorDate, CustomerContract."Currency Code"); diff --git a/src/Apps/W1/Subscription Billing/App/Import/Codeunits/CreateSubContractLine.Codeunit.al b/src/Apps/W1/Subscription Billing/App/Import/Codeunits/CreateSubContractLine.Codeunit.al index dac467856f..94a9860d0d 100644 --- a/src/Apps/W1/Subscription Billing/App/Import/Codeunits/CreateSubContractLine.Codeunit.al +++ b/src/Apps/W1/Subscription Billing/App/Import/Codeunits/CreateSubContractLine.Codeunit.al @@ -86,7 +86,7 @@ codeunit 8007 "Create Sub. Contract Line" OldDimSetID := ServiceCommitment."Dimension Set ID"; ServiceCommitment."Subscription Contract No." := CustomerContractLine."Subscription Contract No."; ServiceCommitment."Subscription Contract Line No." := CustomerContractLine."Line No."; - ServiceCommitment.GetCombinedDimensionSetID(ServiceCommitment."Dimension Set ID", CustomerContract."Dimension Set ID"); + ServiceCommitment.SetDefaultDimensions(true); ServiceCommitment.Modify(true); ServiceCommitment.UpdateRelatedVendorServiceCommDimensions(OldDimSetID, ServiceCommitment."Dimension Set ID"); end; @@ -132,7 +132,7 @@ codeunit 8007 "Create Sub. Contract Line" ServiceCommitment."Subscription Contract No." := VendorContractLine."Subscription Contract No."; ServiceCommitment."Subscription Contract Line No." := VendorContractLine."Line No."; - ServiceCommitment.GetCombinedDimensionSetID(ServiceCommitment."Dimension Set ID", VendorContract."Dimension Set ID"); + ServiceCommitment.SetDefaultDimensions(true); ServiceCommitment.Modify(false); VendorContractLine.UpdateServiceCommitmentDimensions(); end; diff --git a/src/Apps/W1/Subscription Billing/App/Service Commitments/Tables/SubscriptionLine.Table.al b/src/Apps/W1/Subscription Billing/App/Service Commitments/Tables/SubscriptionLine.Table.al index 541b482c7a..cf4cd21f79 100644 --- a/src/Apps/W1/Subscription Billing/App/Service Commitments/Tables/SubscriptionLine.Table.al +++ b/src/Apps/W1/Subscription Billing/App/Service Commitments/Tables/SubscriptionLine.Table.al @@ -3,8 +3,11 @@ namespace Microsoft.SubscriptionBilling; using Microsoft.Finance.Currency; using Microsoft.Finance.Dimension; using Microsoft.Finance.GeneralLedger.Account; +using Microsoft.Foundation.AuditCodes; using Microsoft.Foundation.Calendar; using Microsoft.Inventory.Item; +using Microsoft.Purchases.Vendor; +using Microsoft.Sales.Customer; using Microsoft.Sales.Document; using Microsoft.Sales.Pricing; using System.Utilities; @@ -1100,8 +1103,16 @@ table 8059 "Subscription Line" internal procedure SetDefaultDimensions(UseSource: Boolean) var ServiceObject: Record "Subscription Header"; + CustomerContract: Record "Customer Subscription Contract"; + VendorContract: Record "Vendor Subscription Contract"; + SourceCodeSetup: Record "Source Code Setup"; DefaultDimSource: List of [Dictionary of [Integer, Code[20]]]; + SourceCode: Code[10]; + InheritFromDimSetID: Integer; + InheritFromTableNo: Integer; begin + SourceCodeSetup.Get(); + if Rec."Invoicing Item No." <> '' then DimMgt.AddDimSource(DefaultDimSource, Database::Item, Rec."Invoicing Item No."); @@ -1115,7 +1126,33 @@ table 8059 "Subscription Line" end; end; - "Dimension Set ID" := DimMgt.GetDefaultDimID(DefaultDimSource, '', "Shortcut Dimension 1 Code", "Shortcut Dimension 2 Code", 0, 0); + case Rec.Partner of + Enum::"Service Partner"::Customer: + begin + SourceCode := SourceCodeSetup.Sales; + if (Rec."Subscription Contract No." <> '') and CustomerContract.Get(Rec."Subscription Contract No.") then begin + InheritFromDimSetID := CustomerContract."Dimension Set ID"; + InheritFromTableNo := Database::Customer; + if CustomerContract."Bill-to Customer No." <> '' then + DimMgt.AddDimSource(DefaultDimSource, Database::Customer, CustomerContract."Bill-to Customer No."); + end; + end; + Enum::"Service Partner"::Vendor: + begin + SourceCode := SourceCodeSetup.Purchases; + if (Rec."Subscription Contract No." <> '') and VendorContract.Get(Rec."Subscription Contract No.") then begin + InheritFromDimSetID := VendorContract."Dimension Set ID"; + InheritFromTableNo := Database::Vendor; + if VendorContract."Pay-to Vendor No." <> '' then + DimMgt.AddDimSource(DefaultDimSource, Database::Vendor, VendorContract."Pay-to Vendor No."); + end; + end; + end; + + "Dimension Set ID" := DimMgt.GetRecDefaultDimID( + Rec, CurrFieldNo, DefaultDimSource, SourceCode, + "Shortcut Dimension 1 Code", "Shortcut Dimension 2 Code", + InheritFromDimSetID, InheritFromTableNo); DimMgt.UpdateGlobalDimFromDimSetID("Dimension Set ID", "Shortcut Dimension 1 Code", "Shortcut Dimension 2 Code"); end; @@ -1233,7 +1270,7 @@ table 8059 "Subscription Line" begin "Currency Code" := CustomerContract."Currency Code"; InitCurrencyData(); - GetCombinedDimensionSetID("Dimension Set ID", CustomerContract."Dimension Set ID"); + SetDefaultDimensions(true); "Exclude from Price Update" := CustomerContract.DefaultExcludeFromPriceUpdate; end; @@ -1241,7 +1278,7 @@ table 8059 "Subscription Line" begin "Currency Code" := VendorContract."Currency Code"; InitCurrencyData(); - GetCombinedDimensionSetID("Dimension Set ID", VendorContract."Dimension Set ID"); + SetDefaultDimensions(true); "Exclude from Price Update" := VendorContract.DefaultExcludeFromPriceUpdate; end; diff --git a/src/Apps/W1/Subscription Billing/App/Vendor Contracts/Tables/VendSubContractLine.Table.al b/src/Apps/W1/Subscription Billing/App/Vendor Contracts/Tables/VendSubContractLine.Table.al index 627325b83b..c95a2d7275 100644 --- a/src/Apps/W1/Subscription Billing/App/Vendor Contracts/Tables/VendSubContractLine.Table.al +++ b/src/Apps/W1/Subscription Billing/App/Vendor Contracts/Tables/VendSubContractLine.Table.al @@ -181,10 +181,10 @@ table 8065 "Vend. Sub. Contract Line" "Subscription Description" := ServiceObject.Description; ServiceCommitment.InitForServiceObject(ServiceObject, "Service Partner"::Vendor); - ServiceCommitment.UpdateFromVendorContract(VendorContract); - ServiceCommitment."Created in Contract line" := true; ServiceCommitment."Subscription Contract No." := Rec."Subscription Contract No."; ServiceCommitment."Subscription Contract Line No." := Rec."Line No."; + ServiceCommitment.UpdateFromVendorContract(VendorContract); + ServiceCommitment."Created in Contract line" := true; ServiceCommitment.Insert(false); "Subscription Line Entry No." := ServiceCommitment."Entry No."; "Subscription Line Description" := ServiceCommitment.Description; diff --git a/src/Apps/W1/Subscription Billing/App/Vendor Contracts/Tables/VendorSubscriptionContract.Table.al b/src/Apps/W1/Subscription Billing/App/Vendor Contracts/Tables/VendorSubscriptionContract.Table.al index eabe29b505..e9010ffc9a 100644 --- a/src/Apps/W1/Subscription Billing/App/Vendor Contracts/Tables/VendorSubscriptionContract.Table.al +++ b/src/Apps/W1/Subscription Billing/App/Vendor Contracts/Tables/VendorSubscriptionContract.Table.al @@ -1607,7 +1607,7 @@ table 8063 "Vendor Subscription Contract" ServiceCommitment."Subscription Contract Line No." := VendorContractLine."Line No."; VendorContract.Get(ServiceCommitment."Subscription Contract No."); - ServiceCommitment.GetCombinedDimensionSetID(ServiceCommitment."Dimension Set ID", VendorContract."Dimension Set ID"); + ServiceCommitment.SetDefaultDimensions(true); if "Currency Code" <> ServiceCommitment."Currency Code" then begin CalculateCurrencyFactor(ServiceCommitment."Subscription Line Start Date", VendorContract."Currency Code"); ServiceCommitment.SetCurrencyData(CurrencyFactor, CurrencyFactorDate, VendorContract."Currency Code"); diff --git a/src/Apps/W1/Subscription Billing/Test/Service Commitments/ServiceCommDimensions.Codeunit.al b/src/Apps/W1/Subscription Billing/Test/Service Commitments/ServiceCommDimensions.Codeunit.al index 2b67c67b3e..1517e593a3 100644 --- a/src/Apps/W1/Subscription Billing/Test/Service Commitments/ServiceCommDimensions.Codeunit.al +++ b/src/Apps/W1/Subscription Billing/Test/Service Commitments/ServiceCommDimensions.Codeunit.al @@ -2,6 +2,7 @@ namespace Microsoft.SubscriptionBilling; using Microsoft.Finance.Dimension; using Microsoft.Finance.GeneralLedger.Setup; +using Microsoft.Foundation.AuditCodes; using Microsoft.Inventory.Item; using Microsoft.Projects.Project.Job; using Microsoft.Purchases.Document; @@ -865,6 +866,55 @@ codeunit 148160 "Service Comm. Dimensions" ServiceCommitment.TestField("Dimension Set ID", NewDimSetID); end; + [Test] + [HandlerFunctions('MessageHandler,ExchangeRateSelectionModalPageHandler')] + procedure RespectDefaultDimensionPrioritiesOnCustomerContractCreation() + var + Customer: Record Customer; + CustomerContract: Record "Customer Subscription Contract"; + DefaultDimension: Record "Default Dimension"; + Dimension: Record Dimension; + CustomerDimensionValue: Record "Dimension Value"; + ItemDimensionValue: Record "Dimension Value"; + Item: Record Item; + ServiceCommitment: Record "Subscription Line"; + ServiceObject: Record "Subscription Header"; + SourceCodeSetup: Record "Source Code Setup"; + begin + // [SCENARIO #8084] Default Dimension Priorities are respected when a Customer Subscription Contract spawns Subscription Lines + Initialize(); + + // [GIVEN] Default Dimension Priorities for source code "Sales": Item = 1 (highest), Customer = 2 + SourceCodeSetup.Get(); + SetDefaultDimensionPriority(SourceCodeSetup.Sales, Database::Item, 1); + SetDefaultDimensionPriority(SourceCodeSetup.Sales, Database::Customer, 2); + + // [GIVEN] A shared dimension with two distinct values for Customer and Item + LibraryDimension.CreateDimension(Dimension); + LibraryDimension.CreateDimensionValue(CustomerDimensionValue, Dimension.Code); + LibraryDimension.CreateDimensionValue(ItemDimensionValue, Dimension.Code); + + // [GIVEN] Customer carries that dimension with one value, Item with another + ContractTestLibrary.CreateCustomer(Customer); + LibraryDimension.CreateDefaultDimension(DefaultDimension, Database::Customer, Customer."No.", Dimension.Code, CustomerDimensionValue.Code); + ContractTestLibrary.CreateItemForServiceObject(Item, false); + LibraryDimension.CreateDefaultDimension(DefaultDimension, Database::Item, Item."No.", Dimension.Code, ItemDimensionValue.Code); + + // [GIVEN] A Service Object created from the Item + ContractTestLibrary.CreateServiceObjectForItemWithServiceCommitments(ServiceObject, Enum::"Invoicing Via"::Contract, false, Item, 1, 0); + ServiceObject.SetHideValidationDialog(true); + ServiceObject.Validate("End-User Customer No.", Customer."No."); + ServiceObject.Modify(false); + + // [WHEN] The Service Object is assigned to a Customer Subscription Contract + ContractTestLibrary.CreateCustomerContractAndCreateContractLinesForItems(CustomerContract, ServiceObject, Customer."No."); + + // [THEN] The Subscription Line carries Item's dim value (Item priority outranks Customer) + ServiceCommitment.SetRange("Subscription Header No.", ServiceObject."No."); + ServiceCommitment.FindFirst(); + VerifyDimensionSetValue(ServiceCommitment."Dimension Set ID", Dimension.Code, ItemDimensionValue.Code); + end; + #endregion Tests #region Procedures @@ -968,6 +1018,22 @@ codeunit 148160 "Service Comm. Dimensions" SalesLine.Modify(true); end; + local procedure SetDefaultDimensionPriority(SourceCode: Code[10]; TableID: Integer; Priority: Integer) + var + DefaultDimensionPriority: Record "Default Dimension Priority"; + begin + if DefaultDimensionPriority.Get(SourceCode, TableID) then begin + DefaultDimensionPriority.Validate(Priority, Priority); + DefaultDimensionPriority.Modify(true); + end else begin + DefaultDimensionPriority.Init(); + DefaultDimensionPriority."Source Code" := SourceCode; + DefaultDimensionPriority."Table ID" := TableID; + DefaultDimensionPriority.Validate(Priority, Priority); + DefaultDimensionPriority.Insert(true); + end; + end; + local procedure VerifyDimensionSetValue(DimensionSetID: Integer; DimensionCode: Code[20]; ExpectedDimensionValueCode: Code[20]) var DimensionSetEntry: Record "Dimension Set Entry"; From 4164523a43066abc96a5af39f705dc7d5211339f Mon Sep 17 00:00:00 2001 From: Franco111000 Date: Wed, 13 May 2026 13:02:14 +0300 Subject: [PATCH 2/3] Subscription Billing: switch to priority-aware merge that preserves custom dims Previous attempt made SubscriptionLine.SetDefaultDimensions priority-aware, but that recomputed the Subscription Line dim from scratch and wiped any already-present custom dimensions, e.g. the auto-insert Customer-Contract dimension propagated via UpdateRelatedVendorServiceCommDimensions to a paired Vendor Subscription Line. New approach: - Revert SetDefaultDimensions to its original Item-only behavior. - Introduce ApplyContractDimensions on Subscription Line. It merges three slots via DimensionManagement.GetCombinedDimensionSetID: current SC dim, Contract dim, and a priority overlay built via DimMgt.GetTableIDsForHigherPriorities + GetRecDefaultDimID containing only Item / G/L Account sources that outrank the Contract partner table per Default Dimension Priority. - UpdateFromCustomerContract / UpdateFromVendorContract and the Pathway B call sites (CreateCustomerContractLineFromServiceCommitment, CreateVendorContractLineFromServiceCommitment, the Import paths) now call ApplyContractDimensions. - Reorders in CustSubContractLine and VendSubContractLine CreateServiceObjectWithServiceCommitment reverted; no longer needed. When no Default Dim Priorities are configured (or when Customer/Vendor outrank Item, the BC default), ApplyContractDimensions degrades to a blind merge with the Contract dim winning on conflict, matching the previous behavior. Only the explicit priority configuration from #8084 (Item over Customer) triggers the overlay slot. Adds cleanup of the Default Dimension Priority rows the new test inserts so they do not leak to downstream tests in the suite. --- .../Tables/CustSubContractLine.Table.al | 4 +- .../CustomerSubscriptionContract.Table.al | 4 +- .../CreateSubContractLine.Codeunit.al | 12 ++- .../Tables/SubscriptionLine.Table.al | 78 ++++++++++--------- .../Tables/VendSubContractLine.Table.al | 4 +- .../VendorSubscriptionContract.Table.al | 4 +- .../ServiceCommDimensions.Codeunit.al | 12 +++ 7 files changed, 73 insertions(+), 45 deletions(-) diff --git a/src/Apps/W1/Subscription Billing/App/Customer Contracts/Tables/CustSubContractLine.Table.al b/src/Apps/W1/Subscription Billing/App/Customer Contracts/Tables/CustSubContractLine.Table.al index 6d388e63eb..73b5e34f38 100644 --- a/src/Apps/W1/Subscription Billing/App/Customer Contracts/Tables/CustSubContractLine.Table.al +++ b/src/Apps/W1/Subscription Billing/App/Customer Contracts/Tables/CustSubContractLine.Table.al @@ -192,10 +192,10 @@ table 8062 "Cust. Sub. Contract Line" "Subscription Description" := ServiceObject.Description; ServiceCommitment.InitForServiceObject(ServiceObject, "Service Partner"::Customer); - ServiceCommitment."Subscription Contract No." := Rec."Subscription Contract No."; - ServiceCommitment."Subscription Contract Line No." := Rec."Line No."; ServiceCommitment.UpdateFromCustomerContract(CustomerContract); ServiceCommitment."Created in Contract line" := true; + ServiceCommitment."Subscription Contract No." := Rec."Subscription Contract No."; + ServiceCommitment."Subscription Contract Line No." := Rec."Line No."; ServiceCommitment.Insert(false); "Subscription Line Entry No." := ServiceCommitment."Entry No."; "Subscription Line Description" := ServiceCommitment.Description; diff --git a/src/Apps/W1/Subscription Billing/App/Customer Contracts/Tables/CustomerSubscriptionContract.Table.al b/src/Apps/W1/Subscription Billing/App/Customer Contracts/Tables/CustomerSubscriptionContract.Table.al index 61271e7cab..83ce7e57d2 100644 --- a/src/Apps/W1/Subscription Billing/App/Customer Contracts/Tables/CustomerSubscriptionContract.Table.al +++ b/src/Apps/W1/Subscription Billing/App/Customer Contracts/Tables/CustomerSubscriptionContract.Table.al @@ -2090,6 +2090,7 @@ table 8052 "Customer Subscription Contract" var ServiceObject: Record "Subscription Header"; CustomerContract: Record "Customer Subscription Contract"; + SourceCodeSetup: Record "Source Code Setup"; OldDimSetID: Integer; InitHarmonizedBillingFields: Boolean; begin @@ -2109,7 +2110,8 @@ table 8052 "Customer Subscription Contract" ServiceCommitment."Subscription Contract No." := CustomerContractLine."Subscription Contract No."; ServiceCommitment."Subscription Contract Line No." := CustomerContractLine."Line No."; - ServiceCommitment.SetDefaultDimensions(true); + SourceCodeSetup.Get(); + ServiceCommitment.ApplyContractDimensions(CustomerContract."Dimension Set ID", SourceCodeSetup.Sales, Database::Customer); if "Currency Code" <> ServiceCommitment."Currency Code" then begin CalculateCurrencyFactor(ServiceCommitment."Subscription Line Start Date", CustomerContract."Currency Code"); ServiceCommitment.SetCurrencyData(CurrencyFactor, CurrencyFactorDate, CustomerContract."Currency Code"); diff --git a/src/Apps/W1/Subscription Billing/App/Import/Codeunits/CreateSubContractLine.Codeunit.al b/src/Apps/W1/Subscription Billing/App/Import/Codeunits/CreateSubContractLine.Codeunit.al index 94a9860d0d..4239f4cb26 100644 --- a/src/Apps/W1/Subscription Billing/App/Import/Codeunits/CreateSubContractLine.Codeunit.al +++ b/src/Apps/W1/Subscription Billing/App/Import/Codeunits/CreateSubContractLine.Codeunit.al @@ -1,5 +1,9 @@ namespace Microsoft.SubscriptionBilling; +using Microsoft.Foundation.AuditCodes; +using Microsoft.Purchases.Vendor; +using Microsoft.Sales.Customer; + codeunit 8007 "Create Sub. Contract Line" { TableNo = "Imported Subscription Line"; @@ -70,6 +74,7 @@ codeunit 8007 "Create Sub. Contract Line" local procedure CreateCustomerContractLine() var CustomerContractLine: Record "Cust. Sub. Contract Line"; + SourceCodeSetup: Record "Source Code Setup"; OldDimSetID: Integer; begin OnBeforeCreateCustomerContractLine(ServiceCommitment, ImportedServiceCommitment); @@ -86,7 +91,8 @@ codeunit 8007 "Create Sub. Contract Line" OldDimSetID := ServiceCommitment."Dimension Set ID"; ServiceCommitment."Subscription Contract No." := CustomerContractLine."Subscription Contract No."; ServiceCommitment."Subscription Contract Line No." := CustomerContractLine."Line No."; - ServiceCommitment.SetDefaultDimensions(true); + SourceCodeSetup.Get(); + ServiceCommitment.ApplyContractDimensions(CustomerContract."Dimension Set ID", SourceCodeSetup.Sales, Database::Customer); ServiceCommitment.Modify(true); ServiceCommitment.UpdateRelatedVendorServiceCommDimensions(OldDimSetID, ServiceCommitment."Dimension Set ID"); end; @@ -117,6 +123,7 @@ codeunit 8007 "Create Sub. Contract Line" local procedure CreateVendorContractLine() var VendorContractLine: Record "Vend. Sub. Contract Line"; + SourceCodeSetup: Record "Source Code Setup"; begin OnBeforeCreateVendorContractLine(ServiceCommitment, ImportedServiceCommitment); if ImportedServiceCommitment.IsContractCommentLine() then @@ -132,7 +139,8 @@ codeunit 8007 "Create Sub. Contract Line" ServiceCommitment."Subscription Contract No." := VendorContractLine."Subscription Contract No."; ServiceCommitment."Subscription Contract Line No." := VendorContractLine."Line No."; - ServiceCommitment.SetDefaultDimensions(true); + SourceCodeSetup.Get(); + ServiceCommitment.ApplyContractDimensions(VendorContract."Dimension Set ID", SourceCodeSetup.Purchases, Database::Vendor); ServiceCommitment.Modify(false); VendorContractLine.UpdateServiceCommitmentDimensions(); end; diff --git a/src/Apps/W1/Subscription Billing/App/Service Commitments/Tables/SubscriptionLine.Table.al b/src/Apps/W1/Subscription Billing/App/Service Commitments/Tables/SubscriptionLine.Table.al index cf4cd21f79..9c277bfe33 100644 --- a/src/Apps/W1/Subscription Billing/App/Service Commitments/Tables/SubscriptionLine.Table.al +++ b/src/Apps/W1/Subscription Billing/App/Service Commitments/Tables/SubscriptionLine.Table.al @@ -1103,16 +1103,8 @@ table 8059 "Subscription Line" internal procedure SetDefaultDimensions(UseSource: Boolean) var ServiceObject: Record "Subscription Header"; - CustomerContract: Record "Customer Subscription Contract"; - VendorContract: Record "Vendor Subscription Contract"; - SourceCodeSetup: Record "Source Code Setup"; DefaultDimSource: List of [Dictionary of [Integer, Code[20]]]; - SourceCode: Code[10]; - InheritFromDimSetID: Integer; - InheritFromTableNo: Integer; begin - SourceCodeSetup.Get(); - if Rec."Invoicing Item No." <> '' then DimMgt.AddDimSource(DefaultDimSource, Database::Item, Rec."Invoicing Item No."); @@ -1126,36 +1118,42 @@ table 8059 "Subscription Line" end; end; - case Rec.Partner of - Enum::"Service Partner"::Customer: - begin - SourceCode := SourceCodeSetup.Sales; - if (Rec."Subscription Contract No." <> '') and CustomerContract.Get(Rec."Subscription Contract No.") then begin - InheritFromDimSetID := CustomerContract."Dimension Set ID"; - InheritFromTableNo := Database::Customer; - if CustomerContract."Bill-to Customer No." <> '' then - DimMgt.AddDimSource(DefaultDimSource, Database::Customer, CustomerContract."Bill-to Customer No."); - end; - end; - Enum::"Service Partner"::Vendor: - begin - SourceCode := SourceCodeSetup.Purchases; - if (Rec."Subscription Contract No." <> '') and VendorContract.Get(Rec."Subscription Contract No.") then begin - InheritFromDimSetID := VendorContract."Dimension Set ID"; - InheritFromTableNo := Database::Vendor; - if VendorContract."Pay-to Vendor No." <> '' then - DimMgt.AddDimSource(DefaultDimSource, Database::Vendor, VendorContract."Pay-to Vendor No."); - end; - end; - end; - - "Dimension Set ID" := DimMgt.GetRecDefaultDimID( - Rec, CurrFieldNo, DefaultDimSource, SourceCode, - "Shortcut Dimension 1 Code", "Shortcut Dimension 2 Code", - InheritFromDimSetID, InheritFromTableNo); + "Dimension Set ID" := DimMgt.GetDefaultDimID(DefaultDimSource, '', "Shortcut Dimension 1 Code", "Shortcut Dimension 2 Code", 0, 0); DimMgt.UpdateGlobalDimFromDimSetID("Dimension Set ID", "Shortcut Dimension 1 Code", "Shortcut Dimension 2 Code"); end; + internal procedure ApplyContractDimensions(ContractDimSetID: Integer; SourceCode: Code[10]; ContractPartnerTableID: Integer) + var + ServiceObject: Record "Subscription Header"; + DefaultDimSource: List of [Dictionary of [Integer, Code[20]]]; + HighPriorityDimSource: List of [Dictionary of [Integer, Code[20]]]; + DimSetIDArr: array[10] of Integer; + TempDimValue1: Code[20]; + TempDimValue2: Code[20]; + begin + DimSetIDArr[1] := "Dimension Set ID"; + DimSetIDArr[2] := ContractDimSetID; + + if Rec."Invoicing Item No." <> '' then + DimMgt.AddDimSource(DefaultDimSource, Database::Item, Rec."Invoicing Item No."); + if ServiceObject.Get("Subscription Header No.") then + case ServiceObject.Type of + ServiceObject.Type::Item: + DimMgt.AddDimSource(DefaultDimSource, Database::Item, ServiceObject."Source No."); + ServiceObject.Type::"G/L Account": + DimMgt.AddDimSource(DefaultDimSource, Database::"G/L Account", ServiceObject."Source No."); + end; + + if DimMgt.GetTableIDsForHigherPriorities(DefaultDimSource, HighPriorityDimSource, SourceCode, ContractPartnerTableID) then + DimSetIDArr[3] := + DimMgt.GetRecDefaultDimID( + Rec, CurrFieldNo, HighPriorityDimSource, SourceCode, + TempDimValue1, TempDimValue2, 0, 0); + + "Dimension Set ID" := + DimMgt.GetCombinedDimensionSetID(DimSetIDArr, "Shortcut Dimension 1 Code", "Shortcut Dimension 2 Code"); + end; + internal procedure GetCombinedDimensionSetID(DimSetID1: Integer; DimSetID2: Integer) var DimSetIDArr: array[10] of Integer; @@ -1267,18 +1265,24 @@ table 8059 "Subscription Line" end; internal procedure UpdateFromCustomerContract(CustomerContract: Record "Customer Subscription Contract") + var + SourceCodeSetup: Record "Source Code Setup"; begin "Currency Code" := CustomerContract."Currency Code"; InitCurrencyData(); - SetDefaultDimensions(true); + SourceCodeSetup.Get(); + ApplyContractDimensions(CustomerContract."Dimension Set ID", SourceCodeSetup.Sales, Database::Customer); "Exclude from Price Update" := CustomerContract.DefaultExcludeFromPriceUpdate; end; internal procedure UpdateFromVendorContract(VendorContract: Record "Vendor Subscription Contract") + var + SourceCodeSetup: Record "Source Code Setup"; begin "Currency Code" := VendorContract."Currency Code"; InitCurrencyData(); - SetDefaultDimensions(true); + SourceCodeSetup.Get(); + ApplyContractDimensions(VendorContract."Dimension Set ID", SourceCodeSetup.Purchases, Database::Vendor); "Exclude from Price Update" := VendorContract.DefaultExcludeFromPriceUpdate; end; diff --git a/src/Apps/W1/Subscription Billing/App/Vendor Contracts/Tables/VendSubContractLine.Table.al b/src/Apps/W1/Subscription Billing/App/Vendor Contracts/Tables/VendSubContractLine.Table.al index c95a2d7275..627325b83b 100644 --- a/src/Apps/W1/Subscription Billing/App/Vendor Contracts/Tables/VendSubContractLine.Table.al +++ b/src/Apps/W1/Subscription Billing/App/Vendor Contracts/Tables/VendSubContractLine.Table.al @@ -181,10 +181,10 @@ table 8065 "Vend. Sub. Contract Line" "Subscription Description" := ServiceObject.Description; ServiceCommitment.InitForServiceObject(ServiceObject, "Service Partner"::Vendor); - ServiceCommitment."Subscription Contract No." := Rec."Subscription Contract No."; - ServiceCommitment."Subscription Contract Line No." := Rec."Line No."; ServiceCommitment.UpdateFromVendorContract(VendorContract); ServiceCommitment."Created in Contract line" := true; + ServiceCommitment."Subscription Contract No." := Rec."Subscription Contract No."; + ServiceCommitment."Subscription Contract Line No." := Rec."Line No."; ServiceCommitment.Insert(false); "Subscription Line Entry No." := ServiceCommitment."Entry No."; "Subscription Line Description" := ServiceCommitment.Description; diff --git a/src/Apps/W1/Subscription Billing/App/Vendor Contracts/Tables/VendorSubscriptionContract.Table.al b/src/Apps/W1/Subscription Billing/App/Vendor Contracts/Tables/VendorSubscriptionContract.Table.al index e9010ffc9a..dbcdb0c6a6 100644 --- a/src/Apps/W1/Subscription Billing/App/Vendor Contracts/Tables/VendorSubscriptionContract.Table.al +++ b/src/Apps/W1/Subscription Billing/App/Vendor Contracts/Tables/VendorSubscriptionContract.Table.al @@ -1598,6 +1598,7 @@ table 8063 "Vendor Subscription Contract" var ServiceObject: Record "Subscription Header"; VendorContract: Record "Vendor Subscription Contract"; + SourceCodeSetup: Record "Source Code Setup"; begin ServiceObject.Get(ServiceCommitment."Subscription Header No."); VendorContractLine.InitFromServiceCommitment(ServiceCommitment, ContractNo); @@ -1607,7 +1608,8 @@ table 8063 "Vendor Subscription Contract" ServiceCommitment."Subscription Contract Line No." := VendorContractLine."Line No."; VendorContract.Get(ServiceCommitment."Subscription Contract No."); - ServiceCommitment.SetDefaultDimensions(true); + SourceCodeSetup.Get(); + ServiceCommitment.ApplyContractDimensions(VendorContract."Dimension Set ID", SourceCodeSetup.Purchases, Database::Vendor); if "Currency Code" <> ServiceCommitment."Currency Code" then begin CalculateCurrencyFactor(ServiceCommitment."Subscription Line Start Date", VendorContract."Currency Code"); ServiceCommitment.SetCurrencyData(CurrencyFactor, CurrencyFactorDate, VendorContract."Currency Code"); diff --git a/src/Apps/W1/Subscription Billing/Test/Service Commitments/ServiceCommDimensions.Codeunit.al b/src/Apps/W1/Subscription Billing/Test/Service Commitments/ServiceCommDimensions.Codeunit.al index 1517e593a3..c9a005eb9c 100644 --- a/src/Apps/W1/Subscription Billing/Test/Service Commitments/ServiceCommDimensions.Codeunit.al +++ b/src/Apps/W1/Subscription Billing/Test/Service Commitments/ServiceCommDimensions.Codeunit.al @@ -913,6 +913,10 @@ codeunit 148160 "Service Comm. Dimensions" ServiceCommitment.SetRange("Subscription Header No.", ServiceObject."No."); ServiceCommitment.FindFirst(); VerifyDimensionSetValue(ServiceCommitment."Dimension Set ID", Dimension.Code, ItemDimensionValue.Code); + + // [CLEANUP] Reset the Default Dimension Priorities we added so subsequent tests run with vanilla settings + ResetDefaultDimensionPriority(SourceCodeSetup.Sales, Database::Item); + ResetDefaultDimensionPriority(SourceCodeSetup.Sales, Database::Customer); end; #endregion Tests @@ -1034,6 +1038,14 @@ codeunit 148160 "Service Comm. Dimensions" end; end; + local procedure ResetDefaultDimensionPriority(SourceCode: Code[10]; TableID: Integer) + var + DefaultDimensionPriority: Record "Default Dimension Priority"; + begin + if DefaultDimensionPriority.Get(SourceCode, TableID) then + DefaultDimensionPriority.Delete(true); + end; + local procedure VerifyDimensionSetValue(DimensionSetID: Integer; DimensionCode: Code[20]; ExpectedDimensionValueCode: Code[20]) var DimensionSetEntry: Record "Dimension Set Entry"; From 9e9dca3993e7f5d37ab89e3423e1a505be6898cd Mon Sep 17 00:00:00 2001 From: Franco111000 Date: Wed, 13 May 2026 20:37:17 +0300 Subject: [PATCH 3/3] Subscription Billing: extract shared dim-source helper and cover cross-link procedures Extracts the duplicated dim-source-building logic from SetDefaultDimensions and ApplyContractDimensions into a local helper AddDefaultDimensionSources on Subscription Line. Switches the Subscription Header lookup from an unguarded Get (errors on missing) to a guarded if Get then (silent skip) so the helper is safe to reuse in both contexts. No caller relies on the previous error path. Extends the priority-aware merge to the two cross-link procedures that previously bypassed it: - CustSubContractLine.DeleteRelatedVendorServiceCommDimensions now applies ApplyContractDimensions(VendorContract.Dim, SourceCodeSetup.Purchases, Database::Vendor) on each paired vendor Subscription Line, so Default Dimension Priority for source code Purchases is honored when the customer contract line is deleted and the vendor lines are recomputed. - VendSubContractLine.UpdateServiceCommitmentDimensions now applies ApplyContractDimensions(CustomerContract.Dim, SourceCodeSetup.Sales, Database::Customer) when propagating Customer Contract dim onto a paired Vendor Subscription Line, so the same Sales priority configuration the rest of the PR respects also flows through the cross-link. Under vanilla BC priority configuration (Customer/Vendor outrank Item by default) the overlay stays empty and the behavior remains identical to the prior blind merge. --- .../Tables/CustSubContractLine.Table.al | 6 ++- .../Tables/SubscriptionLine.Table.al | 43 ++++++++----------- .../Tables/VendSubContractLine.Table.al | 9 +++- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/Apps/W1/Subscription Billing/App/Customer Contracts/Tables/CustSubContractLine.Table.al b/src/Apps/W1/Subscription Billing/App/Customer Contracts/Tables/CustSubContractLine.Table.al index 73b5e34f38..d677156e9a 100644 --- a/src/Apps/W1/Subscription Billing/App/Customer Contracts/Tables/CustSubContractLine.Table.al +++ b/src/Apps/W1/Subscription Billing/App/Customer Contracts/Tables/CustSubContractLine.Table.al @@ -1,7 +1,9 @@ namespace Microsoft.SubscriptionBilling; using Microsoft.Finance.GeneralLedger.Account; +using Microsoft.Foundation.AuditCodes; using Microsoft.Inventory.Item; +using Microsoft.Purchases.Vendor; using System.Utilities; table 8062 "Cust. Sub. Contract Line" @@ -338,13 +340,15 @@ table 8062 "Cust. Sub. Contract Line" var VendorServiceCommitment: Record "Subscription Line"; VendorContract: Record "Vendor Subscription Contract"; + SourceCodeSetup: Record "Source Code Setup"; begin + SourceCodeSetup.Get(); VendorServiceCommitment.FilterOnServiceObjectAndPackage(ServiceCommitment."Subscription Header No.", ServiceCommitment.Template, ServiceCommitment."Subscription Package Code", Enum::"Service Partner"::Vendor); if VendorServiceCommitment.FindSet() then repeat VendorServiceCommitment.SetDefaultDimensions(true); if VendorContract.Get(VendorServiceCommitment."Subscription Contract No.") then - VendorServiceCommitment.GetCombinedDimensionSetID(VendorServiceCommitment."Dimension Set ID", VendorContract."Dimension Set ID"); + VendorServiceCommitment.ApplyContractDimensions(VendorContract."Dimension Set ID", SourceCodeSetup.Purchases, Database::Vendor); VendorServiceCommitment.Modify(false); until VendorServiceCommitment.Next() = 0; end; diff --git a/src/Apps/W1/Subscription Billing/App/Service Commitments/Tables/SubscriptionLine.Table.al b/src/Apps/W1/Subscription Billing/App/Service Commitments/Tables/SubscriptionLine.Table.al index 9c277bfe33..6004563cb6 100644 --- a/src/Apps/W1/Subscription Billing/App/Service Commitments/Tables/SubscriptionLine.Table.al +++ b/src/Apps/W1/Subscription Billing/App/Service Commitments/Tables/SubscriptionLine.Table.al @@ -1102,29 +1102,15 @@ table 8059 "Subscription Line" internal procedure SetDefaultDimensions(UseSource: Boolean) var - ServiceObject: Record "Subscription Header"; DefaultDimSource: List of [Dictionary of [Integer, Code[20]]]; begin - if Rec."Invoicing Item No." <> '' then - DimMgt.AddDimSource(DefaultDimSource, Database::Item, Rec."Invoicing Item No."); - - if UseSource then begin - ServiceObject.Get("Subscription Header No."); - case ServiceObject.Type of - ServiceObject.Type::Item: - DimMgt.AddDimSource(DefaultDimSource, Database::Item, ServiceObject."Source No."); - ServiceObject.Type::"G/L Account": - DimMgt.AddDimSource(DefaultDimSource, Database::"G/L Account", ServiceObject."Source No."); - end; - end; - + AddDefaultDimensionSources(DefaultDimSource, UseSource); "Dimension Set ID" := DimMgt.GetDefaultDimID(DefaultDimSource, '', "Shortcut Dimension 1 Code", "Shortcut Dimension 2 Code", 0, 0); DimMgt.UpdateGlobalDimFromDimSetID("Dimension Set ID", "Shortcut Dimension 1 Code", "Shortcut Dimension 2 Code"); end; internal procedure ApplyContractDimensions(ContractDimSetID: Integer; SourceCode: Code[10]; ContractPartnerTableID: Integer) var - ServiceObject: Record "Subscription Header"; DefaultDimSource: List of [Dictionary of [Integer, Code[20]]]; HighPriorityDimSource: List of [Dictionary of [Integer, Code[20]]]; DimSetIDArr: array[10] of Integer; @@ -1134,15 +1120,7 @@ table 8059 "Subscription Line" DimSetIDArr[1] := "Dimension Set ID"; DimSetIDArr[2] := ContractDimSetID; - if Rec."Invoicing Item No." <> '' then - DimMgt.AddDimSource(DefaultDimSource, Database::Item, Rec."Invoicing Item No."); - if ServiceObject.Get("Subscription Header No.") then - case ServiceObject.Type of - ServiceObject.Type::Item: - DimMgt.AddDimSource(DefaultDimSource, Database::Item, ServiceObject."Source No."); - ServiceObject.Type::"G/L Account": - DimMgt.AddDimSource(DefaultDimSource, Database::"G/L Account", ServiceObject."Source No."); - end; + AddDefaultDimensionSources(DefaultDimSource, true); if DimMgt.GetTableIDsForHigherPriorities(DefaultDimSource, HighPriorityDimSource, SourceCode, ContractPartnerTableID) then DimSetIDArr[3] := @@ -1154,6 +1132,23 @@ table 8059 "Subscription Line" DimMgt.GetCombinedDimensionSetID(DimSetIDArr, "Shortcut Dimension 1 Code", "Shortcut Dimension 2 Code"); end; + local procedure AddDefaultDimensionSources(var DefaultDimSource: List of [Dictionary of [Integer, Code[20]]]; UseSource: Boolean) + var + ServiceObject: Record "Subscription Header"; + begin + if Rec."Invoicing Item No." <> '' then + DimMgt.AddDimSource(DefaultDimSource, Database::Item, Rec."Invoicing Item No."); + + if UseSource then + if ServiceObject.Get("Subscription Header No.") then + case ServiceObject.Type of + ServiceObject.Type::Item: + DimMgt.AddDimSource(DefaultDimSource, Database::Item, ServiceObject."Source No."); + ServiceObject.Type::"G/L Account": + DimMgt.AddDimSource(DefaultDimSource, Database::"G/L Account", ServiceObject."Source No."); + end; + end; + internal procedure GetCombinedDimensionSetID(DimSetID1: Integer; DimSetID2: Integer) var DimSetIDArr: array[10] of Integer; diff --git a/src/Apps/W1/Subscription Billing/App/Vendor Contracts/Tables/VendSubContractLine.Table.al b/src/Apps/W1/Subscription Billing/App/Vendor Contracts/Tables/VendSubContractLine.Table.al index 627325b83b..3929110dfb 100644 --- a/src/Apps/W1/Subscription Billing/App/Vendor Contracts/Tables/VendSubContractLine.Table.al +++ b/src/Apps/W1/Subscription Billing/App/Vendor Contracts/Tables/VendSubContractLine.Table.al @@ -1,7 +1,9 @@ namespace Microsoft.SubscriptionBilling; using Microsoft.Finance.GeneralLedger.Account; +using Microsoft.Foundation.AuditCodes; using Microsoft.Inventory.Item; +using Microsoft.Sales.Customer; using System.Utilities; table 8065 "Vend. Sub. Contract Line" @@ -306,6 +308,7 @@ table 8065 "Vend. Sub. Contract Line" ServiceCommitment: Record "Subscription Line"; CustomerServiceCommitment: Record "Subscription Line"; CustomerContract: Record "Customer Subscription Contract"; + SourceCodeSetup: Record "Source Code Setup"; begin if Rec."Subscription Header No." = '' then exit; @@ -315,8 +318,10 @@ table 8065 "Vend. Sub. Contract Line" ServiceCommitment.SetDefaultDimensions(true); CustomerServiceCommitment.FilterOnServiceObjectAndPackage(Rec."Subscription Header No.", ServiceCommitment.Template, ServiceCommitment."Subscription Package Code", Enum::"Service Partner"::Customer); if CustomerServiceCommitment.FindFirst() then - if CustomerContract.Get(CustomerServiceCommitment."Subscription Contract No.") then - ServiceCommitment.GetCombinedDimensionSetID(ServiceCommitment."Dimension Set ID", CustomerContract."Dimension Set ID"); + if CustomerContract.Get(CustomerServiceCommitment."Subscription Contract No.") then begin + SourceCodeSetup.Get(); + ServiceCommitment.ApplyContractDimensions(CustomerContract."Dimension Set ID", SourceCodeSetup.Sales, Database::Customer); + end; ServiceCommitment.Modify(false); end;