Skip to content

Commit d95fa44

Browse files
mynjjJoshua Martínez Pineda
andauthored
Reintroduce direct historical line matching for E-Document drafts (#7602)
## Summary - Wire up `FindRelatedPurchaseLineInHistory` (previously dead code) as a direct matching step before the AI pipeline in `E-Doc. Historical Matching` - Sets `E-Doc. Purch. Line History Id` on matched lines, enabling the source invoice link and additional fields features - If all lines resolve via direct history, the AI pipeline is skipped entirely Fixes [AB#630431](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/630431) Co-authored-by: Joshua Martínez Pineda <diegojoshuam@microsoft.com>
1 parent d576951 commit d95fa44

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

src/Apps/W1/EDocument/App/src/Processing/AI/Tools/EDocHistoricalMatching.Codeunit.al

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ codeunit 6177 "E-Doc. Historical Matching" implements "AOAI Function", IEDocAISy
5151
HistoricalMatchingExperimentTok: Label 'EDocHistoricalMatchingExperiment', Locked = true;
5252
HistoricalMatchingConfig: Text;
5353
begin
54+
if DirectHistoricalMatch(Rec) then
55+
exit;
56+
5457
// Get experiment configuration
5558
HistoricalMatchingConfig := FeatureConfiguration.GetConfiguration(HistoricalMatchingExperimentTok);
5659

@@ -90,6 +93,44 @@ codeunit 6177 "E-Doc. Historical Matching" implements "AOAI Function", IEDocAISy
9093
FeatureTelemetry.LogUsage('0000PUP', EDocumentAIProcessor.GetEDocumentMatchingAssistanceName(), GetFeatureName(), TelemetryDimensions);
9194
end;
9295

96+
local procedure DirectHistoricalMatch(var SourceEDocumentPurchaseLine: Record "E-Document Purchase Line"): Boolean
97+
var
98+
EDocumentPurchaseLine: Record "E-Document Purchase Line";
99+
EDocumentPurchaseHeader: Record "E-Document Purchase Header";
100+
EDocPurchaseLineHistory: Record "E-Doc. Purchase Line History";
101+
PurchInvLine: Record "Purch. Inv. Line";
102+
EDocPurchaseHistMapping: Codeunit "E-Doc. Purchase Hist. Mapping";
103+
EDocImpSessionTelemetry: Codeunit "E-Doc. Imp. Session Telemetry";
104+
VendorNo: Code[20];
105+
DirectHistoricalMatchEventTok: Label 'Direct Historical Match', Locked = true;
106+
begin
107+
EDocumentPurchaseLine.Copy(SourceEDocumentPurchaseLine);
108+
if not EDocumentPurchaseLine.FindFirst() then
109+
exit(false);
110+
111+
EDocumentPurchaseHeader.SetRange("E-Document Entry No.", EDocumentPurchaseLine."E-Document Entry No.");
112+
if EDocumentPurchaseHeader.FindFirst() then
113+
VendorNo := EDocumentPurchaseHeader."[BC] Vendor No.";
114+
if VendorNo = '' then
115+
exit(false);
116+
117+
if EDocumentPurchaseLine.FindSet() then
118+
repeat
119+
if EDocumentPurchaseLine."[BC] Purchase Type No." = '' then
120+
if EDocPurchaseHistMapping.FindRelatedPurchaseLineInHistory(VendorNo, EDocumentPurchaseLine, EDocPurchaseLineHistory) then
121+
if PurchInvLine.GetBySystemId(EDocPurchaseLineHistory."Purch. Inv. Line SystemId") then begin
122+
EDocPurchaseHistMapping.UpdateMissingLineValuesFromHistory(PurchInvLine, EDocumentPurchaseLine, '', 'High');
123+
EDocumentPurchaseLine."E-Doc. Purch. Line History Id" := EDocPurchaseLineHistory."Entry No.";
124+
EDocumentPurchaseLine.Modify(true);
125+
EDocImpSessionTelemetry.SetLineBool(EDocumentPurchaseLine.SystemId, DirectHistoricalMatchEventTok, true);
126+
end;
127+
until EDocumentPurchaseLine.Next() = 0;
128+
129+
// If no unmatched lines remain, all lines were resolved directly
130+
EDocumentPurchaseLine.SetRange("[BC] Purchase Type No.", '');
131+
exit(EDocumentPurchaseLine.IsEmpty());
132+
end;
133+
93134
local procedure GetConfidenceScore(ExperimentConfig: Text): Text
94135
begin
95136
// When in control group we match exact vendor, hence score baseline is high confidence, else medium confidence

src/Apps/W1/EDocument/App/src/Processing/Import/Purchase/History/EDocPurchaseHistMapping.Codeunit.al

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ codeunit 6120 "E-Doc. Purchase Hist. Mapping"
159159
if UnitOfMeasure.Get(PurchInvLine."Unit of Measure") then // we only assign if it's a valid unit of measure
160160
EDocumentPurchaseLine."[BC] Unit of Measure" := CopyStr(PurchInvLine."Unit of Measure", 1, MaxStrLen(EDocumentPurchaseLine."[BC] Unit of Measure"));
161161

162-
if (EDocumentPurchaseLine."[BC] Purchase Line Type" = "Purchase Line Type"::" ") and (EDocumentPurchaseLine."[BC] Purchase Type No." = '') then begin
162+
if EDocumentPurchaseLine."[BC] Purchase Type No." = '' then begin
163163
// We first check if the purchase invoice line came from an allocation account line
164164
// If so, we set the account type and number explictly since the type and number of the line has changed
165165
if not IsNullGuid(PurchInvLine."Alloc. Purch. Line SystemId") then begin

0 commit comments

Comments
 (0)