Hello everyone,
I’m facing an issue when trying to automatically attach an XML file to a Batch Job in Dynamics 365 Finance & Operations.
I am generating an XML file inside a class that extends RunBaseBatch.
After generating the file, I want to attach it to the Batch Job.
What works
-
The batch job executes successfully.
-
The XML file is generated correctly.
-
The DocuRef + DocuValue records are created in SQL with the correct:
-
RefRecId= BatchJob RecId-
RefTableId= 12070 (BatchJob) -
RefCompanyId= correct company -
File is saved through
IDocumentStorageProvider.SaveFile
-
What does NOT work
The attachment does not appear in the Batch Job form.
I have checked SQL and the DocuRef/DocuValue entries are created correctly, but the UI does not show the attachment.
I also tried using the class DocuManagement (method attachFileForReference), but I still get the same result.
{
XmlSAFTGenerator xmlSAFTGenerator;
str result;
_nameFile,
_auditFileVersion,
_taxAccountingBasis,
_startDate,
_endDate,
_fiscalYear
);
str xmlFileName = _nameFile + ".xml";
str xmlFilePath = System.IO.Path::GetTempPath() + xmlFileName;
this.attachFileToBatchJob(_batchJobId, xmlFileName, xmlFilePath);
}
private void attachFileToBatchJob(RefRecId _batchJob, str _xmlFileName, str _filePath)
{
DocuRef docuRef;
DocuValue docuValue;
DocumentLocation location;
IDocumentStorageProvider storageProvider;
new System.IO.MemoryStream(System.IO.File::ReadAllBytes(_filePath));
storageProvider = Docu::GetStorageProvider(docType, true, curUserId());
docuValue.clear();
docuValue.FileId = newGuid();
docuValue.OriginalFileName = _xmlFileName;
docuValue.FileName = _xmlFileName;
docuValue.Name = _xmlFileName;
docuValue.FileType = "xml";
docuValue.StorageProviderId = storageProvider.ProviderId;
docuValue.FileId,
storageProvider.GenerateUniqueName(_xmlFileName),
"application/xml",
fileStream
);
{
if (location.get_NavigationUri())
docuValue.Path = location.get_NavigationUri().ToString();
docuValue.AccessInformation = location.get_AccessUri().ToString();
}
ttsCommit;
docuRef.clear();
docuRef.RefTableId = tableNum(BatchJob);
docuRef.RefRecId = _batchJob;
docuRef.RefCompanyId = curext();
docuRef.TypeId = "File";
docuRef.Name = _xmlFileName;
docuRef.ValueRecId = docuValue.RecId;
docuRef.insert();
ttsCommit;
}
Has anyone successfully attached documents to a Batch Job?
Any help, guidance, or working example would be greatly appreciated.
Thank you!


Report
All responses (
Answers (