https://magnomgp.github.io/electronic-reporting-configure-the-vendor-payment-filename/
https://d365ffo.com/2022/01/23/ax-d365fo-electronic-reporting-set-output-file-name/comment-page-1/
File name expression should be added at 2 places
1.ISO20022CTReports
2.XMLHeader
For Destination setting we need to configure at
[ExtensionOf(tableStr(BankParameters))]
final class DTB_BankParameters_T_Extension
{
public boolean validateBankPaymentSetup()
{
boolean flag;
if(this.BlobPublicKeyBankPayment != null &&
this.BlobReferenceBankPayment != null &&
this.BlobAccountNameBankPayment != null)
{
flag = true;
}
return flag;
}
}
-------------------------------------------------------------------------
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
[ExtensionOf(classStr(CustVendOutPaym))]
final class DTB_CustVendOutPaym_C_Extension
{
/// <summary>
/// closeFile() COC which saves the filestream to Azure Blob
/// </summary>
public void closeFile()
{
#File
BankParameters bankParameters = BankParameters::find();
if(bankParameters.validateBankPaymentSetup())
{
#File
//#FilePathDelimiter
StreamIo extnFile = file;
file = null;
System.IO.MemoryStream extnMemStream = extnFile.getStream();
var bytes = extnMemStream.ToArray();
try
{
using (System.IO.FileStream extnFileStrm = System.IO.File::Create(fileName, System.IO.FileMode::OpenOrCreate))
{
extnFileStrm.Seek(0, System.IO.SeekOrigin::End);
extnFileStrm.Write(bytes, 0, bytes.Length);
str azureStorageAccount = bankParameters.BlobAccountNameBankPayment;//Storage account name
str azureStorageAccessKey = bankParameters.BlobPublicKeyBankPayment;//Access key of storage account
str azureContainerReference = bankParameters.BlobReferenceBankPayment;//Container name
var storageCredentials = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(azureStorageAccount, azureStorageAccessKey);
CloudStorageAccount storageAccount = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(storageCredentials, true);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer destinationCloudBlobContainer = blobClient.GetContainerReference(azureContainerReference);
CloudBlockBlob destinationBlob = destinationCloudBlobContainer.GetBlockBlobReference(fileName);
if (extnFileStrm.CanSeek)
{
extnFileStrm.Seek(0, System.IO.SeekOrigin::Begin);
}
destinationBlob.uploadFromStream(extnFileStrm, null, null, null);
}
}
catch(Exception::Error)
{
error("@DTBSD:DTB_OperationCannotBeCompleted");
}
}
else
{
warning(strFmt("@DTBSD:DTB_BankPaymentFileOutboundMandatoryFields"));
}
next closeFile();
}
}
------------------------------------------------------------------------------------------------------------
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
class DTB_ERVendPaymOutFieUploadHelper
{
/// <summary>
/// Handles attachingFile event from Electronic reporting
/// </summary>
/// <param name = "_args">Event args for event handler</param> [SubscribesTo(classStr(ERDocuManagementEvents), staticDelegateStr(ERDocuManagementEvents, attachingFile))]
[SubscribesTo(classStr(ERDocuManagementEvents), staticDelegateStr(ERDocuManagementEvents, attachingFile))]
public static void ERDocuManagementEvents_attachingFile(ERDocuManagementAttachingFileEventArgs _args)
{
ERFormatMappingRunJobTable ERFormatMappingRunJobTable;
Common common = _args.getOwner();
if(common.tableid == tableNum(ERFormatMappingRunJobTable))
{
ERFormatMappingRunJobTable = ERFormatMappingRunJobTable::find(common.RecId);
}
if (!_args.isHandled() && ERFormatMappingRunJobTable.Archived == noyes::No)
{
BankParameters bankParameters = BankParameters::find();
if(_args.getDocuTypeId() == bankParameters.DocuTypeIdBankPayment)
{
DTB_ERVendPaymOutFieUploadHelper uploadHandler = DTB_ERVendPaymOutFieUploadHelper::construct();
uploadHandler.uploadFile(_args.getStream(), _args.getAttachmentName(), bankParameters);
}
else
{
warning(strFmt("@DTBSD:DTB_WarningDocuTypeShouldMatchBankPaymOutbound"));
}
}
}
/// <summary>
/// Constructor method
/// </summary>
/// <returns>DTB_ERVendPaymOutFieUploadHelper class object</returns>
public static DTB_ERVendPaymOutFieUploadHelper construct()
{
return new DTB_ERVendPaymOutFieUploadHelper();
}
/// <summary>
/// Uploads file to Azure blob container
/// </summary>
/// <param name = "_fileStream">File stream</param>
/// <returns>Returns boolean</returns>
private boolean uploadFile(System.IO.Stream _fileStream,
str _attachmentName,
BankParameters _bankParameters)
{
boolean ret = true;
try
{
if(_bankParameters.validateBankPaymentSetup())
{
str azureStorageAccount = _bankParameters.BlobAccountNameBankPayment;//Storage account name
str azureStorageAccessKey = _bankParameters.BlobPublicKeyBankPayment;//Access key of storage account
str azureContainerReference = _bankParameters.BlobReferenceBankPayment;//Container name
var storageCredentials = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(azureStorageAccount, azureStorageAccessKey);
CloudStorageAccount storageAccount = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(storageCredentials, true);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer destinationCloudBlobContainer = blobClient.GetContainerReference(azureContainerReference);
CloudBlockBlob destinationBlob = destinationCloudBlobContainer.GetBlockBlobReference(_attachmentName);
if (_fileStream.CanSeek)
{
_fileStream.Seek(0, System.IO.SeekOrigin::Begin);
}
destinationBlob.UploadFromStream(_fileStream, null, null, null);
}
else
{
warning(strFmt("@DTBSD:DTB_BankPaymentFileOutboundMandatoryFields"));
}
Info(strFmt("@DTBSD:DTB_SuccessUploadAzureBlobBankPaymOutbound"));
}
catch(Exception::Error)
{
ret = error("@DTBSD:DTB_OperationCannotBeCompleted");
}
return ret;
}
}
Add fields to bank parameters table and form
Add fields to bank parameters table and form
No comments:
Post a Comment