Event subscriber ExportCustomerDocumentsOnBeforeSendToDisk in CU13622 makes using Custom codeunit in Document Sending Profile impossible
Due to lack of event publishers in OIOUBL module I have tried to make a custom codeunit to be used for OIOUBL and has made the following setup in Electronic Document Formats.

This codeunit is basically a copy of Codeunit 13636 with a modified ExportXML function.
While trying to send a Posted Sales Invoice using Send and select Save to Disk, because of event ExportCustomerDocumentsOnBeforeSendToDisk in CU13622, I am forced to make my codeunit to RunOn table 112. But if I send run Send and select Email, I will get error that my codeunit should run on table 62!
So my question is - Does the event subscriber ExportCustomerDocumentsOnBeforeSendToDisk really necessary?
Hi @StanPesotskiy I saw that you have tagged this issue as a "even-request" so I wonder what is the intended way to resolve this?
Adding a new event in the ExportXML() function of codeunit 13636?
I don't know the solution. This an internal tagging to distribute requests to right people.
May I know if this issue is been looking into?
Do let me know if you need more information from my end. Or if I should take a different approach to solve the challenge I am facing.
By the way, the standard OIOUBL produce XML by filtering away Sales Invoice Line and I need to apply a different filters to the Sales Invoice Line to produce the XML that I need according to our solution to our customer.
Hi @StanPesotskiy is it possible to get some update on this issue?
Thanks.
Hi, it is still in the backlog. We have to pause the events implementation now due to finalization of the the major release.
I checked the issue, got the same result, the code in my comment below works only for saving OIOUBL document, not for sending email.
@hsiungw After you set your own codeunit on the Electronic Document Formats page, it just runs as Codeunit.Run(<YourCOD>, SalesInvoiceHeader). So you should have proper code in OnRun trigger of your codeunit.
In your case you should replace all the code in OnRun() trigger of COD60018 to one line:
ExportXML(SalesInvoiceHeader);
Please try it and report the results.
Hi @AleksanderGladkov,
When sending electronic document format user can choose if they want the XML to be saved to disk and/or email to customer.
The issue here is, if I am using a custom codeunit in the setup, then I found that (1) If I make codeunit 60018 work with Save to disk, I will get an error while choose to email the XML (2) If I make codeunit 60018 work with email, then I will get an error while trying to save it to disk.
The problem is the event subscriber ExportCustomerDocumentsOnBeforeSendToDisk in codeunit 13622 that is doing the following: ... ExportCodeunitID := OIOUBLManagement.GetExportCodeunitID(RecordVariant); IsStandardExportCodeunit := OIOUBLManagement.IsStandardExportCodeunitID(ExportCodeunitID);
if not IsStandardExportCodeunit then begin Codeunit.Run(ExportCodeunitID, RecordVariant); // If not standard CU the codeunit is expected to run on T112 IsHandled := true; exit; end;
case RecRef.Number() of Database::"Sales Invoice Header": begin RecRef.SetTable(SalesInvoiceHeader); SalesInvoiceHeader.FindSet(); repeat OIOUBLExportSalesInvoice.ExportXML(SalesInvoiceHeader); // The standard CU run on T61 is fine because T112 is executed in ExportXML instead of OnRun()!!! OIOUBLManagement.WriteLogSalesInvoice(SalesInvoiceHeader); until SalesInvoiceHeader.Next() = 0; end; ...
Suggestion:
Maybe there should be a new event so that I can escape from ExportCustomerDocumentsOnBeforeSendToDisk so that I can then subscribe to OnBeforeSendToDisk of table "Document Sending Profile" to handle save to disk in my custom codeunit 60018?
Hi @AleksanderGladkov are you able to look into my suggestion or getting what I am trying to explain?
Hi @StanPesotskiy I have tried to explain the situation so if this case has the correct tagging?
@hsiungw Yes, I read your explanation and reproduced this problem, thanks.
I am going to add a new event to OIOUBLSubscribers.Codeunit.al:
[IntegrationEvent(false, false)]
local procedure OnBeforeRunNonStandardCodeunit(ExportCodeunitID: Integer; RecordVariant: Variant; var IsHandled: Boolean)
begin
end;
It is going to be run from ExportCustomerDocumentsOnBeforeSendToDisk():
if not IsStandardExportCodeunit then begin
OnBeforeRunNonStandardCodeunit(ExportCodeunitID, RecordVariant, IsHandled);
if IsHandled then
exit;
Codeunit.Run(ExportCodeunitID, RecordVariant);
IsHandled := true;
exit;
end;
Will it solve your problem?
Hi @AleksanderGladkov,
I can confirm that the new event OnBeforeRunNonStandardCodeunit() will help and solve my need.
Can you proceed with adding that new event?
Thanks!
Yes, we will be adding it.
Thanks for reporting this. We agree, and we’ll publish a fix asap, either in an update for the current version or in the next major release. We will update this issue with information about availability.
Thanks for submitting this issue. We will publish a fix for it in the next minor update for release 17.