Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Apps/W1/EDocument/App/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
{
"from": 6234,
"to": 6234
},
{
"from": 6401,
"to": 6410
}
],
"resourceExposurePolicy": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,16 @@ codeunit 6140 "E-Doc. Import"
var
EDocDraftSessionTelemetry: Codeunit "E-Doc. Imp. Session Telemetry";
EDocumentErrorHelper: Codeunit "E-Document Error Helper";
EDocImportErrorContext: Codeunit "E-Doc. Import Error Context";
LastErrorText: Text;
begin
EDocumentErrorHelper.ClearErrorMessages(EDocument);
Commit();
BindSubscription(EDocImportErrorContext);
if not ImportEDocumentProcess.Run() then begin
LastErrorText := GetLastErrorText();
if LastErrorText <> '' then begin // We don't insert an error when empty, following the convention of empty error meaning "operation cancelled by user"
LastErrorText := EDocImportErrorContext.WrapErrorMessage(LastErrorText);
EDocument.SetRecFilter();
EDocument.FindFirst();

Expand All @@ -154,8 +157,10 @@ codeunit 6140 "E-Doc. Import"
end;
EDocDraftSessionTelemetry.SetText('Step', Format(ImportEDocumentProcess.GetStep()));
EDocDraftSessionTelemetry.SetBool('Success', false);
UnbindSubscription(EDocImportErrorContext);
exit(false);
end;
UnbindSubscription(EDocImportErrorContext);
exit(true);
end;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------
namespace Microsoft.eServices.EDocument.Processing.Import;

codeunit 6199 "E-Doc. Import Error Context"
{
Access = Internal;
InherentEntitlements = X;
InherentPermissions = X;
EventSubscriberInstance = Manual;

var
CurrentContext: Text;
AdditionalFieldContextLbl: Label 'While applying additional field "%1" (ID %2) with value ''%3''', Comment = '%1 = Field Name, %2 = Field Number, %3 = Value';
ValidatingFieldLbl: Label 'While validating field "%1"', Comment = '%1 = Field Caption';
WrapErrorLbl: Label '%1: %2', Comment = '%1 = Context, %2 = Original Error';

/// <summary>
/// Returns whether a context message is currently set.
/// </summary>
/// <returns>True if a context message is set, false otherwise.</returns>
procedure HasContext(): Boolean
begin
exit(CurrentContext <> '');
end;

/// <summary>
/// Wraps the original error message with the current context, if one is set.
/// </summary>
/// <param name="OriginalError">The original error message to wrap.</param>
/// <returns>The error message prefixed with the current context, or the original message if no context is set.</returns>
procedure WrapErrorMessage(OriginalError: Text): Text
begin
if CurrentContext = '' then
exit(OriginalError);
exit(StrSubstNo(WrapErrorLbl, CurrentContext, OriginalError));
end;

/// <summary>
/// Clears the additional field context
/// </summary>
procedure ClearAdditionalFieldContext()
begin
CurrentContext := '';
end;

[EventSubscriber(ObjectType::Codeunit, Codeunit::"E-Doc. Import Error Context", OnValidateFieldWithContext, '', false, false)]
local procedure ValidateFieldWithContextSubscriber(FieldCaption: Text)
begin
CurrentContext := StrSubstNo(ValidatingFieldLbl, FieldCaption);
end;

[EventSubscriber(ObjectType::Codeunit, Codeunit::"E-Doc. Import Error Context", OnSetAdditionalFieldContext, '', false, false)]
local procedure SetAdditionalFieldContext(FieldName: Text; FieldNo: Integer; Value: Text)
begin
CurrentContext := StrSubstNo(AdditionalFieldContextLbl, FieldName, FieldNo, Value);
end;

/// <summary>
/// Sets the context to describe a field being validated during e-document import.
/// </summary>
/// <param name="FieldCaption">The caption of the field being validated.</param>
[IntegrationEvent(false, false)]
procedure OnValidateFieldWithContext(FieldCaption: Text)
begin
end;

/// <summary>
/// Sets the context to describe an additional field being applied
/// </summary>
/// <param name="FieldName">The name of the additional field being applied.</param>
/// <param name="FieldNo">The ID of the additional field being applied.</param>
/// <param name="Value">The value being applied to the field.</param>
[IntegrationEvent(false, false)]
procedure OnSetAdditionalFieldContext(FieldName: Text; FieldNo: Integer; Value: Text)
begin
end;
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ codeunit 6117 "E-Doc. Create Purchase Invoice" implements IEDocumentFinishDraft,
EDocumentPurchaseLine: Record "E-Document Purchase Line";
PurchaseLine: Record "Purchase Line";
EDocRecordLink: Record "E-Doc. Record Link";
EDocPurchaseDocumentHelper: Codeunit "E-Doc. Purch. Doc. Helper";
PurchCalcDiscByType: Codeunit "Purch - Calc Disc. By Type";
EDocLineByReceipt: Query "E-Doc. Line by Receipt";
LastReceiptNo: Code[20];
Expand All @@ -132,9 +133,9 @@ codeunit 6117 "E-Doc. Create Purchase Invoice" implements IEDocumentFinishDraft,
PurchaseHeader."Pay-to Vendor No." := EDocumentPurchaseHeader."[BC] Vendor No.";
PurchaseHeader."Posting Description" := EDocumentPurchaseHeader."Posting Description";
if EDocumentPurchaseHeader."Document Date" <> 0D then
PurchaseHeader.Validate("Document Date", EDocumentPurchaseHeader."Document Date");
EDocPurchaseDocumentHelper.ValidateFieldWithContext(PurchaseHeader, PurchaseHeader.FieldNo("Document Date"), EDocumentPurchaseHeader."Document Date");
if EDocumentPurchaseHeader."Due Date" <> 0D then
PurchaseHeader.Validate("Due Date", EDocumentPurchaseHeader."Due Date");
EDocPurchaseDocumentHelper.ValidateFieldWithContext(PurchaseHeader, PurchaseHeader.FieldNo("Due Date"), EDocumentPurchaseHeader."Due Date");

VendorInvoiceNo := CopyStr(EDocumentPurchaseHeader."Sales Invoice No.", 1, MaxStrLen(PurchaseHeader."Vendor Invoice No."));
VendorLedgerEntry.SetLoadFields("Entry No.");
Expand All @@ -145,7 +146,7 @@ codeunit 6117 "E-Doc. Create Purchase Invoice" implements IEDocumentFinishDraft,
Error(InvoiceAlreadyExistsErr, VendorInvoiceNo, EDocumentPurchaseHeader."[BC] Vendor No.");
end;

PurchaseHeader.Validate("Vendor Invoice No.", VendorInvoiceNo);
EDocPurchaseDocumentHelper.ValidateFieldWithContext(PurchaseHeader, PurchaseHeader.FieldNo("Vendor Invoice No."), VendorInvoiceNo);
PurchaseHeader.Insert(true);

PurchaseHeader."Invoice Received Date" := PurchaseHeader."Document Date";
Expand All @@ -154,7 +155,7 @@ codeunit 6117 "E-Doc. Create Purchase Invoice" implements IEDocumentFinishDraft,
// Validate of currency has to happen after insert.
GLSetup.GetRecordOnce();
if EDocumentPurchaseHeader."Currency Code" <> GLSetup.GetCurrencyCode('') then begin
PurchaseHeader.Validate("Currency Code", EDocumentPurchaseHeader."Currency Code");
EDocPurchaseDocumentHelper.ValidateFieldWithContext(PurchaseHeader, PurchaseHeader.FieldNo("Currency Code"), EDocumentPurchaseHeader."Currency Code");
PurchaseHeader.Modify();
end;
EDocRecordLink.InsertEDocumentHeaderLink(EDocumentPurchaseHeader, PurchaseHeader);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------
namespace Microsoft.eServices.EDocument.Processing.Import;

using Microsoft.Purchases.Document;

/// <summary>
/// Shared logic for creating BC purchase documents (invoices and credit memos) from e-document draft data.
/// </summary>
codeunit 6402 "E-Doc. Purch. Doc. Helper"
{
Access = Internal;
InherentEntitlements = X;
InherentPermissions = X;

procedure ValidateFieldWithContext(var Rec: Record "Purchase Header"; FieldNo: Integer; Value: Variant)
var
VariantRec: Variant;
begin
VariantRec := Rec;
ValidateFieldWithContext(VariantRec, FieldNo, Value);
Rec := VariantRec;
end;

local procedure ValidateFieldWithContext(var RecVariant: Variant; FieldNo: Integer; Value: Variant)
var
EDocImportErrorContext: Codeunit "E-Doc. Import Error Context";
RecRef: RecordRef;
FldRef: FieldRef;
begin
RecRef.GetTable(RecVariant);
FldRef := RecRef.Field(FieldNo);
EDocImportErrorContext.OnValidateFieldWithContext(FldRef.Caption());
FldRef.Validate(Value);
RecRef.SetTable(RecVariant);
end;
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,10 @@ codeunit 6120 "E-Doc. Purchase Hist. Mapping"
var
EDocPurchLineFieldSetup: Record "ED Purchase Line Field Setup";
EDocPurchLineField: Record "E-Document Line - Field";
EDocImportErrorContext: Codeunit "E-Doc. Import Error Context";
NewPurchLineRecordRef: RecordRef;
NewPurchLineFieldRef: FieldRef;
FieldValue: Variant;
begin
if not EDocPurchLineFieldSetup.FindSet() then
exit;
Expand All @@ -223,7 +225,10 @@ codeunit 6120 "E-Doc. Purchase Hist. Mapping"
continue;
EDocPurchLineField.Get(EDocumentPurchaseLine, EDocPurchLineFieldSetup);
NewPurchLineFieldRef := NewPurchLineRecordRef.Field(EDocPurchLineFieldSetup."Field No.");
NewPurchLineFieldRef.Validate(EDocPurchLineField.GetValue());
FieldValue := EDocPurchLineField.GetValue();
EDocImportErrorContext.OnSetAdditionalFieldContext(NewPurchLineFieldRef.Name(), EDocPurchLineFieldSetup."Field No.", EDocPurchLineField.GetValueAsText());
NewPurchLineFieldRef.Validate(FieldValue);
EDocImportErrorContext.ClearAdditionalFieldContext();
until EDocPurchLineFieldSetup.Next() = 0;
NewPurchLineRecordRef.SetTable(PurchaseLine);
end;
Expand Down
Loading
Loading