Hi,
In this post we will view the X++ code to save the payment file generated during "Generate payments" process. To facilitate the process, created Chain of Commands for method closeFile of class CustVendOutPaym.
Step 1: Create an extension for class CustVendOutPaym and using CoC wrap the closeFile method.
[ExtensionOf(classStr(CustVendOutPaym))]
final class CGCustVendOutPaym_Extension
{
public void closeFile()
{
}
}
Step 2: Provide definition for the method closeFile to capture the generated file and save to a physical location. Used methods of class System.IO.File for this operation.
[ExtensionOf(classStr(CustVendOutPaym))]
final class CGCustVendOutPaym_Extension
{
public void closeFile()
{
#File
//#FilePathDelimiter
str filePath = @'C:\PaymentFile\' + fileName;
StreamIo extnFile = file;
file = null;
System.IO.MemoryStream extnMemStream = extnFile.getStream();
var bytes = extnMemStream.ToArray();
using (System.IO.FileStream extnFileStrm = System.IO.File::Create(filePath, System.IO.FileMode::OpenOrCreate))
{
extnFileStrm.Seek(0, System.IO.SeekOrigin::End);
extnFileStrm.Write(bytes, 0, bytes.Length);
}
next closeFile();
}
}
Step 3: Build the code. Select the payment journal and click on "Generate payments" button to open Generate payments dialog. Click on Ok button on parameters dialog to view the output message and payment file in the desired location. In my case the path is "C:\PaymentFile\" on the local machine.
Thanks,
Chaitanya Golla
*This post is locked for comments