From d448162cd32950f3f15485e46b96b189db8ee222 Mon Sep 17 00:00:00 2001 From: dayland Date: Wed, 29 Oct 2025 11:22:43 +0000 Subject: [PATCH 1/2] Simplify UpdateMissingLineValuesFromHistory and restore activity log type - Remove overload that accepted E-Doc. Purchase Line History (no longer sets the draft's history id or telemetry). - Use a single UpdateMissingLineValuesFromHistory signature with an explicit ExplanationTxt parameter and stop merging with a default explanation. - Ensure Activity Log builder explicitly sets the Activity Log Type (AI). --- .../EDocPurchaseHistMapping.Codeunit.al | 35 +++---------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/src/Apps/W1/EDocument/App/src/Processing/Import/Purchase/History/EDocPurchaseHistMapping.Codeunit.al b/src/Apps/W1/EDocument/App/src/Processing/Import/Purchase/History/EDocPurchaseHistMapping.Codeunit.al index c053da95a6..9373177c98 100644 --- a/src/Apps/W1/EDocument/App/src/Processing/Import/Purchase/History/EDocPurchaseHistMapping.Codeunit.al +++ b/src/Apps/W1/EDocument/App/src/Processing/Import/Purchase/History/EDocPurchaseHistMapping.Codeunit.al @@ -119,48 +119,20 @@ codeunit 6120 "E-Doc. Purchase Hist. Mapping" end; end; - /// - /// Takes a draft line EDocumentPurchaseLine and the corresponding historic record found for it EDocPurchaseLineHistory. - /// If the values on the draft line have already been set by other mechanisms we don't assign it to avoid overwriting it. - /// - /// - /// - procedure UpdateMissingLineValuesFromHistory(EDocPurchaseLineHistory: Record "E-Doc. Purchase Line History"; var EDocumentPurchaseLine: Record "E-Document Purchase Line"; CustomExplanationTxt: Text[250]) - var - PurchInvLine: Record "Purch. Inv. Line"; - begin - // If there is no such Purchase Invoice Line we can't apply any values to the draft - if not PurchInvLine.GetBySystemId(EDocPurchaseLineHistory."Purch. Inv. Line SystemId") then - exit; - - UpdateMissingLineValuesFromHistory(PurchInvLine, EDocumentPurchaseLine, CustomExplanationTxt); - - // We mark this draft with the historic match for future application of the additional fields - EDocumentPurchaseLine."E-Doc. Purch. Line History Id" := EDocPurchaseLineHistory."Entry No."; - EDocImpSessionTelemetry.SetLineBool(EDocumentPurchaseLine.SystemId, 'Line History', true); - end; - /// /// Takes a draft line EDocumentPurchaseLine and the corresponding historic record found for it PurchInvLine. /// If the values on the draft line have already been set by other mechanisms we don't assign it to avoid overwriting it. /// /// /// - procedure UpdateMissingLineValuesFromHistory(PurchInvLine: Record "Purch. Inv. Line"; var EDocumentPurchaseLine: Record "E-Document Purchase Line"; CustomExplanationTxt: Text[250]) + procedure UpdateMissingLineValuesFromHistory(PurchInvLine: Record "Purch. Inv. Line"; var EDocumentPurchaseLine: Record "E-Document Purchase Line"; ExplanationTxt: Text[250]) var PurchInvHeader: Record "Purch. Inv. Header"; DeferralTemplate: Record "Deferral Template"; UnitOfMeasure: Record "Unit of Measure"; EDocActivityLogSession: Codeunit "E-Doc. Activity Log Session"; DeferralActivityLog, AccountNumberActivityLog : Codeunit "Activity Log Builder"; - ExplanationTxt: Label 'Line value was retrieved from posted purchase invoice history. See source for details.'; - CurrentExplanationTxt: Text[250]; begin - if CustomExplanationTxt <> '' then - CurrentExplanationTxt := CopyStr(CustomExplanationTxt, 1, MaxStrLen(CurrentExplanationTxt)) - else - CurrentExplanationTxt := ExplanationTxt; - PurchInvHeader.SetRange("No.", PurchInvLine."Document No."); if not PurchInvHeader.FindFirst() then exit; @@ -171,7 +143,7 @@ codeunit 6120 "E-Doc. Purchase Hist. Mapping" if EDocumentPurchaseLine."[BC] Deferral Code" = '' then if DeferralTemplate.Get(PurchInvLine."Deferral Code") then begin // we only assign if it's a valid deferral template EDocumentPurchaseLine."[BC] Deferral Code" := PurchInvLine."Deferral Code"; - SetActivityLog(EDocumentPurchaseLine.SystemId, EDocumentPurchaseLine.FieldNo("[BC] Deferral Code"), PurchInvHeader, CurrentExplanationTxt, DeferralActivityLog, EDocActivityLogSession.DeferralTok()); + SetActivityLog(EDocumentPurchaseLine.SystemId, EDocumentPurchaseLine.FieldNo("[BC] Deferral Code"), PurchInvHeader, ExplanationTxt, DeferralActivityLog, EDocActivityLogSession.DeferralTok()); end; if EDocumentPurchaseLine."[BC] Shortcut Dimension 1 Code" = '' then EDocumentPurchaseLine."[BC] Shortcut Dimension 1 Code" := PurchInvLine."Shortcut Dimension 1 Code"; @@ -193,7 +165,7 @@ codeunit 6120 "E-Doc. Purchase Hist. Mapping" end; // If we assigned something in this if-branch, we set the activity log if (EDocumentPurchaseLine."[BC] Purchase Line Type" <> "Purchase Line Type"::" ") or (EDocumentPurchaseLine."[BC] Purchase Type No." <> '') then - SetActivityLog(EDocumentPurchaseLine.SystemId, EDocumentPurchaseLine.FieldNo("[BC] Purchase Type No."), PurchInvHeader, CurrentExplanationTxt, AccountNumberActivityLog, EDocActivityLogSession.AccountNumberTok()); + SetActivityLog(EDocumentPurchaseLine.SystemId, EDocumentPurchaseLine.FieldNo("[BC] Purchase Type No."), PurchInvHeader, ExplanationTxt, AccountNumberActivityLog, EDocActivityLogSession.AccountNumberTok()); end; end; @@ -218,6 +190,7 @@ codeunit 6120 "E-Doc. Purchase Hist. Mapping" ActivityLog .Init(Database::"E-Document Purchase Line", FieldNo, SystemId) .SetExplanation(Reasoning) + .SetType(Enum::"Activity Log Type"::"AI") .SetReferenceSource(Page::"Posted Purchase Invoice", RecordRef) .SetReferenceTitle(StrSubstNo(HistoricalExplanationTxt, PurchInvHeader.GetFilter("No."))); EDocActivityLogSession.Set(ActivityLogSessionToken, ActivityLog); From 9c4956a0951614e2116defa9d8828e75c7b0fb50 Mon Sep 17 00:00:00 2001 From: dayland Date: Wed, 29 Oct 2025 13:13:04 +0000 Subject: [PATCH 2/2] Add overload back in as expermental changes not yet in main --- .../EDocPurchaseHistMapping.Codeunit.al | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Apps/W1/EDocument/App/src/Processing/Import/Purchase/History/EDocPurchaseHistMapping.Codeunit.al b/src/Apps/W1/EDocument/App/src/Processing/Import/Purchase/History/EDocPurchaseHistMapping.Codeunit.al index 9373177c98..9415ae1f06 100644 --- a/src/Apps/W1/EDocument/App/src/Processing/Import/Purchase/History/EDocPurchaseHistMapping.Codeunit.al +++ b/src/Apps/W1/EDocument/App/src/Processing/Import/Purchase/History/EDocPurchaseHistMapping.Codeunit.al @@ -119,6 +119,27 @@ codeunit 6120 "E-Doc. Purchase Hist. Mapping" end; end; + /// + /// Takes a draft line EDocumentPurchaseLine and the corresponding historic record found for it EDocPurchaseLineHistory. + /// If the values on the draft line have already been set by other mechanisms we don't assign it to avoid overwriting it. + /// + /// + /// + procedure UpdateMissingLineValuesFromHistory(EDocPurchaseLineHistory: Record "E-Doc. Purchase Line History"; var EDocumentPurchaseLine: Record "E-Document Purchase Line"; CustomExplanationTxt: Text[250]) + var + PurchInvLine: Record "Purch. Inv. Line"; + begin + // If there is no such Purchase Invoice Line we can't apply any values to the draft + if not PurchInvLine.GetBySystemId(EDocPurchaseLineHistory."Purch. Inv. Line SystemId") then + exit; + + UpdateMissingLineValuesFromHistory(PurchInvLine, EDocumentPurchaseLine, CustomExplanationTxt); + + // We mark this draft with the historic match for future application of the additional fields + EDocumentPurchaseLine."E-Doc. Purch. Line History Id" := EDocPurchaseLineHistory."Entry No."; + EDocImpSessionTelemetry.SetLineBool(EDocumentPurchaseLine.SystemId, 'Line History', true); + end; + /// /// Takes a draft line EDocumentPurchaseLine and the corresponding historic record found for it PurchInvLine. /// If the values on the draft line have already been set by other mechanisms we don't assign it to avoid overwriting it.