Hi, everybody.
Found myself once again with a tricky error.
I programmed a functionality, that runs on both client and server, that attaches both the XML & PDF files for the CFDI 3.3 Electronic Invoice to the sales order and the invoice.
If I execute the process on Client, it displays an infolog message that both files were saved successfully. Then, in AX I open the sales order and on the menu I click the Attachments button to confirm the files are attached to the order and displaying in the document handling form; so far my process runs smoothly and without errors.
However, the problem comes when that same process runs on batch. I check into the Logs of my process in the Batch Job History form, and it displays two messages:
- One is an infolog that states the PDF was sucessfully saved.
- The other is a warning that the directory does not exists.
If I go back to the sales order and open the document handling form, I confirm that the PDF file has been attached to the order but not the XML file, hence, I assume the "directory does not exists" error is linked to the problem that the XML files won't be created if the process runs on batch.
When I was first programming this process in earlier stages I used the EInvoiceReadWriteFile_MX class to generate the XML files, but after I ran the first developer tests on batch from the results in the batch history log I got errors. Then, I analyze the class' properties and understood it runs only on Client, that's why it cannot run in a batch process.
What I chose to circumvent that hurdle was duplicating the class and made the needed tweaks so that the duplicate class runs on Server.
After that, I implemented the calls of the duplicated class in code within the overall process flow.
This is the method's code for my process to call the duplicate class when executing in batch:
protected void generateXMLDocExport(FilePath _filePath, EInvoiceJour_MX _eInvoiceJour_MX, boolean _isInBatch = false)
{
#define.FilePrefix('XML_')
CustInvoiceJour custInvoiceJour = CustInvoiceJour::findRecId(_eInvoiceJour_MX.RefRecId);
EInvoiceReadWriteFile_MX fileWriter;
Copy_EInvoiceReadWriteFile_MX copy_fileWriter;
Filename invoiceFileName;
if (!_isInBatch)
{
fileWriter = EInvoiceReadWriteFile_MX::newWriteFile(_filePath);
}
else
{
//new FileIOPermission(_filePath, #io_write).assert();
copy_fileWriter = Copy_EInvoiceReadWriteFile_MX::newWriteFile(_filePath);
//CodeAccessPermission::revertAssert();
}
invoiceFileName = #FilePrefix + custInvoiceJour.InvoiceId;
try
{
if (!_isInBatch)
{
fileWriter.write(_eInvoiceJour_MX.XMLDoc);
}
else
{
//new FileIOPermission(_filePath, #io_write).assert();
copy_fileWriter.write(_eInvoiceJour_MX.XMLDoc);
//CodeAccessPermission::revertAssert();
}
info(strFmt("@SYS341181", invoiceFileName));
}
catch
{
System.IO.File::Delete(_filePath);
error(strFmt("@SYS341182", invoiceFileName));
}
At first I thought the error could be linked to missing permissions, but since the PDF files are still created when the whole process executes in batch the issue lies somewhere else; I mean both XML and PDF files are saved in the same folder.
What else could be causing the issue?