From 5747016aab5ff969b56dac2b86b3b8fe4f21b1eb Mon Sep 17 00:00:00 2001 From: georgepomazkov Date: Mon, 18 May 2026 12:56:53 +0300 Subject: [PATCH 1/3] Handle failure to manually create E-Document from posted doc with no explicit error --- .../EDocIssuedFinChargeMemo.PageExt.al | 5 +++- .../Extensions/EDocIssuedReminder.PageExt.al | 5 +++- .../EDocPostedSalesCrMemo.PageExt.al | 5 +++- .../Extensions/EDocPostedSalesInv.PageExt.al | 5 +++- .../EDocPostedSalesShipment.PageExt.al | 5 +++- .../EDocPostedServiceCrMemo.PageExt.al | 5 +++- .../EDocPostedServiceInv.PageExt.al | 5 +++- .../EDocPostedTransferShpmnt.PageExt.al | 5 +++- .../EDocumentProcessing.Codeunit.al | 23 ++++++++++++++++++- 9 files changed, 54 insertions(+), 9 deletions(-) diff --git a/src/Apps/W1/EDocument/App/src/Extensions/EDocIssuedFinChargeMemo.PageExt.al b/src/Apps/W1/EDocument/App/src/Extensions/EDocIssuedFinChargeMemo.PageExt.al index b2c48f532b..a5e7a1ee45 100644 --- a/src/Apps/W1/EDocument/App/src/Extensions/EDocIssuedFinChargeMemo.PageExt.al +++ b/src/Apps/W1/EDocument/App/src/Extensions/EDocIssuedFinChargeMemo.PageExt.al @@ -41,7 +41,9 @@ pageextension 6149 "E-Doc. Issued Fin. Charge Memo" extends "Issued Finance Char EDocumentProcessing: Codeunit "E-Document Processing"; begin if EDocumentProcessing.CreateEDocumentFromPostedDocumentPage(Rec, Enum::"E-Document Type"::"Issued Finance Charge Memo") then - Message(EDocumentCreatedMsg); + Message(EDocumentCreatedMsg) + else + Message(EDocumentNotCreatedMsg); end; } } @@ -51,6 +53,7 @@ pageextension 6149 "E-Doc. Issued Fin. Charge Memo" extends "Issued Finance Char var EDocumentExists: Boolean; EDocumentCreatedMsg: Label 'The e-document has been created.'; + EDocumentNotCreatedMsg: Label 'The e-document could not be created.'; trigger OnAfterGetRecord() var diff --git a/src/Apps/W1/EDocument/App/src/Extensions/EDocIssuedReminder.PageExt.al b/src/Apps/W1/EDocument/App/src/Extensions/EDocIssuedReminder.PageExt.al index 888c08f32e..3fa9139451 100644 --- a/src/Apps/W1/EDocument/App/src/Extensions/EDocIssuedReminder.PageExt.al +++ b/src/Apps/W1/EDocument/App/src/Extensions/EDocIssuedReminder.PageExt.al @@ -41,7 +41,9 @@ pageextension 6148 "E-Doc. Issued Reminder" extends "Issued Reminder" EDocumentProcessing: Codeunit "E-Document Processing"; begin if EDocumentProcessing.CreateEDocumentFromPostedDocumentPage(Rec, Enum::"E-Document Type"::"Issued Reminder") then - Message(EDocumentCreatedMsg); + Message(EDocumentCreatedMsg) + else + Message(EDocumentNotCreatedMsg); end; } } @@ -51,6 +53,7 @@ pageextension 6148 "E-Doc. Issued Reminder" extends "Issued Reminder" var EDocumentExists: Boolean; EDocumentCreatedMsg: Label 'The e-document has been created.'; + EDocumentNotCreatedMsg: Label 'The e-document could not be created.'; trigger OnAfterGetRecord() var diff --git a/src/Apps/W1/EDocument/App/src/Extensions/EDocPostedSalesCrMemo.PageExt.al b/src/Apps/W1/EDocument/App/src/Extensions/EDocPostedSalesCrMemo.PageExt.al index c1029e73e5..e5c800ba0f 100644 --- a/src/Apps/W1/EDocument/App/src/Extensions/EDocPostedSalesCrMemo.PageExt.al +++ b/src/Apps/W1/EDocument/App/src/Extensions/EDocPostedSalesCrMemo.PageExt.al @@ -42,7 +42,9 @@ pageextension 6145 "E-Doc. Posted Sales Cr. Memo" extends "Posted Sales Credit M EDocumentProcessing: Codeunit "E-Document Processing"; begin if EDocumentProcessing.CreateEDocumentFromPostedDocumentPage(Rec, Enum::"E-Document Type"::"Sales Credit Memo") then - Message(EDocumentCreatedMsg); + Message(EDocumentCreatedMsg) + else + Message(EDocumentNotCreatedMsg); end; } } @@ -52,6 +54,7 @@ pageextension 6145 "E-Doc. Posted Sales Cr. Memo" extends "Posted Sales Credit M var EDocumentExists: Boolean; EDocumentCreatedMsg: Label 'The e-document has been created.'; + EDocumentNotCreatedMsg: Label 'The e-document could not be created.'; trigger OnAfterGetRecord() var diff --git a/src/Apps/W1/EDocument/App/src/Extensions/EDocPostedSalesInv.PageExt.al b/src/Apps/W1/EDocument/App/src/Extensions/EDocPostedSalesInv.PageExt.al index dd1c81311b..7d99fe69d8 100644 --- a/src/Apps/W1/EDocument/App/src/Extensions/EDocPostedSalesInv.PageExt.al +++ b/src/Apps/W1/EDocument/App/src/Extensions/EDocPostedSalesInv.PageExt.al @@ -41,7 +41,9 @@ pageextension 6144 "E-Doc. Posted Sales Inv." extends "Posted Sales Invoice" EDocumentProcessing: Codeunit "E-Document Processing"; begin if EDocumentProcessing.CreateEDocumentFromPostedDocumentPage(Rec, Enum::"E-Document Type"::"Sales Invoice") then - Message(EDocumentCreatedMsg); + Message(EDocumentCreatedMsg) + else + Message(EDocumentNotCreatedMsg); end; } } @@ -51,6 +53,7 @@ pageextension 6144 "E-Doc. Posted Sales Inv." extends "Posted Sales Invoice" var EDocumentExists: Boolean; EDocumentCreatedMsg: Label 'The e-document has been created.'; + EDocumentNotCreatedMsg: Label 'The e-document could not be created.'; trigger OnAfterGetRecord() var diff --git a/src/Apps/W1/EDocument/App/src/Extensions/EDocPostedSalesShipment.PageExt.al b/src/Apps/W1/EDocument/App/src/Extensions/EDocPostedSalesShipment.PageExt.al index cda4e5f0c1..c6a98241ef 100644 --- a/src/Apps/W1/EDocument/App/src/Extensions/EDocPostedSalesShipment.PageExt.al +++ b/src/Apps/W1/EDocument/App/src/Extensions/EDocPostedSalesShipment.PageExt.al @@ -41,7 +41,9 @@ pageextension 6103 "E-Doc. Posted Sales Shipment" extends "Posted Sales Shipment EDocumentProcessing: Codeunit "E-Document Processing"; begin if EDocumentProcessing.CreateEDocumentFromPostedDocumentPage(Rec, Enum::"E-Document Type"::"Sales Shipment") then - Message(EDocumentCreatedMsg); + Message(EDocumentCreatedMsg) + else + Message(EDocumentNotCreatedMsg); end; } } @@ -51,6 +53,7 @@ pageextension 6103 "E-Doc. Posted Sales Shipment" extends "Posted Sales Shipment var EDocumentExists: Boolean; EDocumentCreatedMsg: Label 'The e-document has been created.'; + EDocumentNotCreatedMsg: Label 'The e-document could not be created.'; trigger OnAfterGetRecord() var diff --git a/src/Apps/W1/EDocument/App/src/Extensions/EDocPostedServiceCrMemo.PageExt.al b/src/Apps/W1/EDocument/App/src/Extensions/EDocPostedServiceCrMemo.PageExt.al index 256a3c44da..889fd39c60 100644 --- a/src/Apps/W1/EDocument/App/src/Extensions/EDocPostedServiceCrMemo.PageExt.al +++ b/src/Apps/W1/EDocument/App/src/Extensions/EDocPostedServiceCrMemo.PageExt.al @@ -41,7 +41,9 @@ pageextension 6143 "E-Doc. Posted Service Cr. Memo" extends "Posted Service Cred EDocumentProcessing: Codeunit "E-Document Processing"; begin if EDocumentProcessing.CreateEDocumentFromPostedDocumentPage(Rec, Enum::"E-Document Type"::"Service Credit Memo") then - Message(EDocumentCreatedMsg); + Message(EDocumentCreatedMsg) + else + Message(EDocumentNotCreatedMsg); end; } } @@ -51,6 +53,7 @@ pageextension 6143 "E-Doc. Posted Service Cr. Memo" extends "Posted Service Cred var EDocumentExists: Boolean; EDocumentCreatedMsg: Label 'The e-document has been created.'; + EDocumentNotCreatedMsg: Label 'The e-document could not be created.'; trigger OnAfterGetRecord() var diff --git a/src/Apps/W1/EDocument/App/src/Extensions/EDocPostedServiceInv.PageExt.al b/src/Apps/W1/EDocument/App/src/Extensions/EDocPostedServiceInv.PageExt.al index 292f7dcfef..0396a0ad2f 100644 --- a/src/Apps/W1/EDocument/App/src/Extensions/EDocPostedServiceInv.PageExt.al +++ b/src/Apps/W1/EDocument/App/src/Extensions/EDocPostedServiceInv.PageExt.al @@ -41,7 +41,9 @@ pageextension 6142 "E-Doc. Posted Service Inv." extends "Posted Service Invoice" EDocumentProcessing: Codeunit "E-Document Processing"; begin if EDocumentProcessing.CreateEDocumentFromPostedDocumentPage(Rec, Enum::"E-Document Type"::"Service Invoice") then - Message(EDocumentCreatedMsg); + Message(EDocumentCreatedMsg) + else + Message(EDocumentNotCreatedMsg); end; } } @@ -51,6 +53,7 @@ pageextension 6142 "E-Doc. Posted Service Inv." extends "Posted Service Invoice" var EDocumentExists: Boolean; EDocumentCreatedMsg: Label 'The e-document has been created.'; + EDocumentNotCreatedMsg: Label 'The e-document could not be created.'; trigger OnAfterGetRecord() var diff --git a/src/Apps/W1/EDocument/App/src/Extensions/EDocPostedTransferShpmnt.PageExt.al b/src/Apps/W1/EDocument/App/src/Extensions/EDocPostedTransferShpmnt.PageExt.al index 3576caf149..b7bb32c6d4 100644 --- a/src/Apps/W1/EDocument/App/src/Extensions/EDocPostedTransferShpmnt.PageExt.al +++ b/src/Apps/W1/EDocument/App/src/Extensions/EDocPostedTransferShpmnt.PageExt.al @@ -44,7 +44,9 @@ pageextension 6106 "E-Doc. Posted Transfer Shpmnt." extends "Posted Transfer Shi EDocumentProcessing: Codeunit "E-Document Processing"; begin if EDocumentProcessing.CreateEDocumentFromPostedDocumentPage(Rec, Enum::"E-Document Type"::"Transfer Shipment") then - Message(EDocumentCreatedMsg); + Message(EDocumentCreatedMsg) + else + Message(EDocumentNotCreatedMsg); end; } } @@ -54,6 +56,7 @@ pageextension 6106 "E-Doc. Posted Transfer Shpmnt." extends "Posted Transfer Shi var EDocumentExists: Boolean; EDocumentCreatedMsg: Label 'The e-document has been created.'; + EDocumentNotCreatedMsg: Label 'The e-document could not be created.'; trigger OnAfterGetRecord() var diff --git a/src/Apps/W1/EDocument/App/src/Processing/EDocumentProcessing.Codeunit.al b/src/Apps/W1/EDocument/App/src/Processing/EDocumentProcessing.Codeunit.al index bfeec0f3cf..993fc5e51e 100644 --- a/src/Apps/W1/EDocument/App/src/Processing/EDocumentProcessing.Codeunit.al +++ b/src/Apps/W1/EDocument/App/src/Processing/EDocumentProcessing.Codeunit.al @@ -139,12 +139,20 @@ codeunit 6108 "E-Document Processing" EDocExport.CheckEDocument(SourceDocumentHeader, EDocumentProcPhase); end; + /// + /// Creates a new E-Document for specified posted document if possible. + /// + /// + /// true if the E-Document has been created; + /// otherwise throws an error or returns false. + /// procedure CreateEDocumentFromPostedDocumentPage(PostedRecord: Variant; DocumentType: Enum "E-Document Type"): Boolean var DocumentSendingProfile: Record "Document Sending Profile"; EDocumentHelper: Codeunit "E-Document Helper"; EDocumentSubscribers: Codeunit "E-Document Subscribers"; RecordRef: RecordRef; + NoOfExistingEDocuments: Integer; ElectronicDocumentErr: Label 'Document sending profile %1 is not setup to send electronic documents.', Comment = '%1 - Document Sending Profile Code'; begin if not PostedRecord.IsRecord() then @@ -155,8 +163,10 @@ codeunit 6108 "E-Document Processing" Error(ElectronicDocumentErr, DocumentSendingProfile.Code); RunEDocumentCheck(PostedRecord, Enum::"E-Document Processing Phase"::Post); + + NoOfExistingEDocuments := this.GetEDocumentCountForDocument(RecordRef); EDocumentSubscribers.CreateEDocumentFromPostedDocument(PostedRecord, DocumentSendingProfile, DocumentType); - exit(true); + exit(this.GetEDocumentCountForDocument(RecordRef) > NoOfExistingEDocuments); end; procedure ProcessEDocumentAsEmail(DocumentSendingProfile: Record "Document Sending Profile"; ReportUsage: Enum "Report Selection Usage"; RecordVariant: Variant; @@ -398,6 +408,17 @@ codeunit 6108 "E-Document Processing" exit(EDocument.Count()); end; + /// + /// Returns the number of existing E-Documents linked to specified document. + /// + procedure GetEDocumentCountForDocument(var SourceDocument: RecordRef): Integer + var + EDocument: Record "E-Document"; + begin + EDocument.SetRange("Document Record ID", SourceDocument.RecordId()); + exit(EDocument.Count()); + end; + procedure MatchedPurchaseOrdersCount(): Integer var PurchaseHeader: Record "Purchase Header"; From 75a74bc4e980eb6a0c4dd0bf6771e2ec60ba63a1 Mon Sep 17 00:00:00 2001 From: georgepomazkov Date: Mon, 18 May 2026 17:52:50 +0300 Subject: [PATCH 2/3] Fix procedure scope --- .../App/src/Processing/EDocumentProcessing.Codeunit.al | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Apps/W1/EDocument/App/src/Processing/EDocumentProcessing.Codeunit.al b/src/Apps/W1/EDocument/App/src/Processing/EDocumentProcessing.Codeunit.al index 993fc5e51e..78123c8cf4 100644 --- a/src/Apps/W1/EDocument/App/src/Processing/EDocumentProcessing.Codeunit.al +++ b/src/Apps/W1/EDocument/App/src/Processing/EDocumentProcessing.Codeunit.al @@ -411,7 +411,7 @@ codeunit 6108 "E-Document Processing" /// /// Returns the number of existing E-Documents linked to specified document. /// - procedure GetEDocumentCountForDocument(var SourceDocument: RecordRef): Integer + local procedure GetEDocumentCountForDocument(var SourceDocument: RecordRef): Integer var EDocument: Record "E-Document"; begin From 149fa440086f65e20a517c57f644422f26eff044 Mon Sep 17 00:00:00 2001 From: georgepomazkov Date: Thu, 21 May 2026 13:04:57 +0300 Subject: [PATCH 3/3] Propagate result of creating E-Document from Posted Document --- .../App/src/Processing/EDocExport.Codeunit.al | 17 +++++++++---- .../EDocumentProcessing.Codeunit.al | 18 ++------------ .../EDocumentSubscribers.Codeunit.al | 24 +++++++++++++++---- 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/src/Apps/W1/EDocument/App/src/Processing/EDocExport.Codeunit.al b/src/Apps/W1/EDocument/App/src/Processing/EDocExport.Codeunit.al index f1230cc8bc..6c07448d07 100644 --- a/src/Apps/W1/EDocument/App/src/Processing/EDocExport.Codeunit.al +++ b/src/Apps/W1/EDocument/App/src/Processing/EDocExport.Codeunit.al @@ -57,7 +57,14 @@ codeunit 6102 "E-Doc. Export" OnAfterEDocumentCheck(EDocSourceRecRef, EDocumentProcessingPhase); end; - internal procedure CreateEDocument(DocumentHeader: RecordRef; DocumentSendingProfile: Record "Document Sending Profile"; EDocumentType: Enum "E-Document Type") + /// + /// Creates a new E-Document of specified type for the provided document header and attempts to export it. + /// + /// + /// true if the E-Document has been created; + /// otherwise false. + /// + internal procedure CreateEDocument(DocumentHeader: RecordRef; DocumentSendingProfile: Record "Document Sending Profile"; EDocumentType: Enum "E-Document Type"): Boolean var WorkFlow: Record Workflow; EDocument: Record "E-Document"; @@ -71,16 +78,16 @@ codeunit 6102 "E-Doc. Export" WorkFlow.TestField(Enabled); if DocumentSendingProfile."Electronic Document" <> DocumentSendingProfile."Electronic Document"::"Extended E-Document Service Flow" then - exit; + exit(false); if not EDocWorkFlowProcessing.GetServicesFromEntryPointResponseInWorkflow(WorkFlow, EDocumentService) then - exit; + exit(false); EDocument."Workflow Code" := WorkFlow.Code; EDocument."Document Sending Profile" := DocumentSendingProfile.Code; if not CreateEDocument(EDocument, DocumentHeader, EDocumentService, EDocumentType) then - exit; + exit(false); // For each service supporting the document type, export it before creating E-Document Created Flow EDocumentServiceStatus.SetRange("E-Document Entry No", EDocument."Entry No"); @@ -95,6 +102,8 @@ codeunit 6102 "E-Doc. Export" until EDocumentServiceStatus.Next() = 0; EDocumentBackgroundJobs.StartEDocumentCreatedFlow(EDocument); + + exit(true); end; /// diff --git a/src/Apps/W1/EDocument/App/src/Processing/EDocumentProcessing.Codeunit.al b/src/Apps/W1/EDocument/App/src/Processing/EDocumentProcessing.Codeunit.al index 78123c8cf4..7ca53f7d43 100644 --- a/src/Apps/W1/EDocument/App/src/Processing/EDocumentProcessing.Codeunit.al +++ b/src/Apps/W1/EDocument/App/src/Processing/EDocumentProcessing.Codeunit.al @@ -144,7 +144,7 @@ codeunit 6108 "E-Document Processing" /// /// /// true if the E-Document has been created; - /// otherwise throws an error or returns false. + /// otherwise false. /// procedure CreateEDocumentFromPostedDocumentPage(PostedRecord: Variant; DocumentType: Enum "E-Document Type"): Boolean var @@ -152,7 +152,6 @@ codeunit 6108 "E-Document Processing" EDocumentHelper: Codeunit "E-Document Helper"; EDocumentSubscribers: Codeunit "E-Document Subscribers"; RecordRef: RecordRef; - NoOfExistingEDocuments: Integer; ElectronicDocumentErr: Label 'Document sending profile %1 is not setup to send electronic documents.', Comment = '%1 - Document Sending Profile Code'; begin if not PostedRecord.IsRecord() then @@ -164,9 +163,7 @@ codeunit 6108 "E-Document Processing" RunEDocumentCheck(PostedRecord, Enum::"E-Document Processing Phase"::Post); - NoOfExistingEDocuments := this.GetEDocumentCountForDocument(RecordRef); - EDocumentSubscribers.CreateEDocumentFromPostedDocument(PostedRecord, DocumentSendingProfile, DocumentType); - exit(this.GetEDocumentCountForDocument(RecordRef) > NoOfExistingEDocuments); + exit(EDocumentSubscribers.CreateEDocumentFromPostedDocument(PostedRecord, DocumentSendingProfile, DocumentType)); end; procedure ProcessEDocumentAsEmail(DocumentSendingProfile: Record "Document Sending Profile"; ReportUsage: Enum "Report Selection Usage"; RecordVariant: Variant; @@ -408,17 +405,6 @@ codeunit 6108 "E-Document Processing" exit(EDocument.Count()); end; - /// - /// Returns the number of existing E-Documents linked to specified document. - /// - local procedure GetEDocumentCountForDocument(var SourceDocument: RecordRef): Integer - var - EDocument: Record "E-Document"; - begin - EDocument.SetRange("Document Record ID", SourceDocument.RecordId()); - exit(EDocument.Count()); - end; - procedure MatchedPurchaseOrdersCount(): Integer var PurchaseHeader: Record "Purchase Header"; diff --git a/src/Apps/W1/EDocument/App/src/Processing/EDocumentSubscribers.Codeunit.al b/src/Apps/W1/EDocument/App/src/Processing/EDocumentSubscribers.Codeunit.al index 5bbcfa482a..7f7abbc220 100644 --- a/src/Apps/W1/EDocument/App/src/Processing/EDocumentSubscribers.Codeunit.al +++ b/src/Apps/W1/EDocument/App/src/Processing/EDocumentSubscribers.Codeunit.al @@ -639,12 +639,26 @@ codeunit 6103 "E-Document Subscribers" EDocLogHelper.InsertLog(EDocument, EDocService, Enum::"E-Document Service Status"::"Imported Document Created"); end; - procedure CreateEDocumentFromPostedDocument(PostedRecord: Variant; DocumentSendingProfile: Record "Document Sending Profile") + /// + /// Creates a new E-Document for the provided posted document if possible. + /// + /// + /// true if the E-Document has been created; + /// otherwise false. + /// + procedure CreateEDocumentFromPostedDocument(PostedRecord: Variant; DocumentSendingProfile: Record "Document Sending Profile"): Boolean begin - CreateEDocumentFromPostedDocument(PostedRecord, DocumentSendingProfile, EDocumentProcessing.GetTypeFromSourceDocument(PostedRecord)); + exit(CreateEDocumentFromPostedDocument(PostedRecord, DocumentSendingProfile, EDocumentProcessing.GetTypeFromSourceDocument(PostedRecord))); end; - procedure CreateEDocumentFromPostedDocument(PostedRecord: Variant; DocumentSendingProfile: Record "Document Sending Profile"; DocumentType: Enum "E-Document Type") + /// + /// Creates a new E-Document of specified type for the provided posted document if possible. + /// + /// + /// true if the E-Document has been created; + /// otherwise false. + /// + procedure CreateEDocumentFromPostedDocument(PostedRecord: Variant; DocumentSendingProfile: Record "Document Sending Profile"; DocumentType: Enum "E-Document Type"): Boolean var TypeHelper: Codeunit "Type Helper"; RecordRef: RecordRef; @@ -658,9 +672,9 @@ codeunit 6103 "E-Document Subscribers" PostedSourceDocumentHeader.GetTable(PostedRecord); if (DocumentSendingProfile."Electronic Document" <> DocumentSendingProfile."Electronic Document"::"Extended E-Document Service Flow") then - exit; + exit(false); - EDocExport.CreateEDocument(PostedSourceDocumentHeader, DocumentSendingProfile, DocumentType); + exit(EDocExport.CreateEDocument(PostedSourceDocumentHeader, DocumentSendingProfile, DocumentType)); end; local procedure PointEDocumentToPostedDocument(OpenRecord: Variant; PostedRecord: Variant; PostedDocumentNo: Code[20]; DocumentType: Enum "E-Document Type")