#define.Note('Note')
str url;
SrsReportRunController controller = new SrsReportRunController();
PayrollContract rdpContract = new PayrollContract();
SRSPrintDestinationSettings srsPrintDestinationSettings;
SysCorpNetPrinters netPrinters;
Filename _filename;
System.Byte[] reportBytes = new System.Byte[0]();
SRSProxy srsProxy;
SRSReportRunService srsReportRunService = new SrsReportRunService();
SRSReportExecutionInfo executionInfo = new SRSReportExecutionInfo();
Microsoft.Dynamics.AX.Framework.Reporting.Shared.ReportingService.ParameterValue[] parameterValueArray;
Map reportParametersMap;
str Note = "Purchase order list report";
List li = new List(Types::String);
li.addEnd("ITCO-00001");
rdpContract.parmRunIDList(li);
Map templateToken = new Map(Types::String, Types::String);
templateToken.insert(#Note, Note);
str tempPath = SysEmailParameters::find().AttachmentsPath;
tempPath = strFmt("%1\\%2", tempPath, "Pending purchase orders");
if (!WinAPI::pathExists(tempPath))
{
WinAPI::createDirectoryPath(tempPath);
}
_filename = strFmt("%1\\Pending purchase orders.pdf", tempPath);
controller.parmReportName(ssrsReportStr(PayrollReport, Report));
controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);
controller.parmShowDialog(false);
controller.parmReportContract().parmRdpContract(rdpContract);
srsPrintDestinationSettings = controller.parmReportContract().parmPrintSettings();
srsPrintDestinationSettings.printMediumType(SRSPrintMediumType::File);
srsPrintDestinationSettings.fileFormat(SRSReportFileFormat::PDF);
srsPrintDestinationSettings.overwriteFile(true);
srsPrintDestinationSettings.fileName(_filename);
srsPrintDestinationSettings.pack();
controller.parmReportContract().parmReportServerConfig(SRSConfiguration::getDefaultServerConfiguration());
controller.parmReportContract().parmReportExecutionInfo(executionInfo);
srsReportRunService.getReportDataContract(controller.parmreportcontract().parmReportName());
srsReportRunService.preRunReport(controller.parmreportcontract());
reportParametersMap = srsReportRunService.createParamMapFromContract(controller.parmReportContract());
parameterValueArray = SrsReportRunUtil::getParameterValueArray(reportParametersMap);
srsProxy = SRSProxy::constructWithConfiguration(controller.parmReportContract().parmReportServerConfig());
// Actual rendering to byte array
reportBytes = srsproxy.renderReportToByteArray(controller.parmreportcontract().parmreportpath(), parameterValueArray,srsPrintDestinationSettings.fileFormat(SRSReportFileFormat::PDF), srsPrintDestinationSettings.deviceinfo());
if (reportBytes)
{
System.IO.Stream stream = new System.IO.MemoryStream(reportBytes);
var fileStream = new System.IO.FileStream(_filename, System.IO.FileMode::Create, System.IO.FileAccess::ReadWrite);
stream.CopyTo(fileStream);
stream.Close();
fileStream.Close();
//url = File::SendFileToTempStore(fileStream, _filename, classstr (FileUploadTemporaryStorageStrategy));
//new Browser().navigate(url, true);
}
SysEmailTable::sendMail("PendingPO", "en-us", "Test@Test.com", templateToken, _filename);
}
Please note that:
The file must be in this path or a subfolder in the path to got sent by sendMail:
SysEmailParameters::find().AttachmentsPath
According to this condition which is inside sendMail:
if (System.IO.File::Exists(htmlDecodedFileName) &&
((new System.IO.FileInfo(htmlDecodedFileName)).Length < (maxAttachmentSize * 1000000)) &&
SysEmailTable::isFromAttachmentsFolder(htmlDecodedFileName))