This
blog guide you how to specify a custom storage location for generated documents
from Electronic reporting (ER) in Dynamics 365 Finance and operations.
Generally
when you generate payments, the payment file is generated, and you're asked to
save it from your web browser to any available location.
Our
client requirement is when they generate payments for vendors, the file should
land automatically to private azure storage blob and from there our integration
is configured such way that the files will be picked from blob and send it to
Bank.
As
we know that ER module classes locked almost and which can’t be reused or extend.
But in out box Microsoft has provided API of the Electronic reporting (ER)
Framework lets you extend the list of storage locations for documents that ER
formats generates.
To
implement the same we need to complete the below steps.¨
Ø
Setup electronic reporting destination settings
Ø
Subscribe to the AttachingFile() event in the class ERDocuManagementEvents and write business logic to save
the file in desired location.
Setup electronic
reporting destination settings:-
1. Document type will be setup to store the file to Azure storage.
2. Electronic reporting destination will be setup to store the
file in the archive as shown below.
Then subscribe to the AttachingFile() event in
the class ERDocuManagementEvents and write business logic to save the file in
desired location:-
[SubscribesTo(classStr(ERDocuManagementEvents),staticDelegateStr(ERDocuManagementEvents,attachingFile))]
public
static void ERDocuManagementEvents_attachingFile (ERDocuManagementAttachingFileEventArgs
_args)
{
if (!_args.isHandled())
{
DocuType docuType = DocuType::find
(_args.getDocuTypeId());
_args.markAsHandled();
var stream = _args.getStream();
if (stream.CanSeek)
{
stream.Seek(0,
System.IO.SeekOrigin::Begin);
}
//Here you can write your
own desired locations where you want to save the file.
// Else you can call C# helper class to save the file to azure blob which
//I discussed in previous post
JP_CloudStorageHelperClass.JP_CloudStorageHelperLocal helperClass = new JP_CloudStorageHelperClass.JP_CloudStorageHelperLocal helperClass();
helperClass.saveFileInBlob(_StorageAccountName,Container, SASKey, BlobName ,
System.IO.Stream stream)
JP_CloudStorageHelperClass.JP_CloudStorageHelperLocal helperClass = new JP_CloudStorageHelperClass.JP_CloudStorageHelperLocal helperClass();
helperClass.saveFileInBlob(_StorageAccountName,Container, SASKey, BlobName ,
System.IO.Stream stream)
}
}
For more info check Microsoft docs, Hope this helps and I will come up with another interesting blog post soon.
Happy Daxing :)
Tags
#D365, #ElectronicReportingDestinationSettings, #SaveCustomLocation, #AzureBlob
ERRORin your code
ReplyDeleteThank you, it would be great if you can help me to identify error.
DeleteHi, Can we do it without developer help?
ReplyDelete1. I created the Document type and set location as Azure storage
2. In electronic reporting destination file destination setting, under archive i selected this document type for my ER file format and also save in job archive.
3. in Azure blob storage configuration, enabled Copy ER to azure blob parameter and in Blob container given the document document type and folder name.
When i am processing my transaction, it is saving into the archive but not going to Azure folder.