[ExtensionOf(classStr(PurchConfirmationJournalPost))]
final class PurchConfirmationJournalPost_TraxSCM_Extension
{
public str CCEmail, Esender;
public void Sendmail()
{
try
{
str vendname = purchTable::find(this.vendPurchOrderJour.purchid).vendorName();
str Purchid = this.vendPurchOrderJour.purchid;
str sUserId;
sUserId = curUserId();
//Getting Email id from User Options --> Account --> Email Provider --> Email id
str userEmail = SysUserInfo::find(sUserId, false).Email;
var builder = new SysMailerMessageBuilder();
builder.setBody(this.Email_Body());
builder.setFrom(userEmail,Esender);
builder.addcc(ccEmail);
builder.setSubject("subject string");
//************
System.IO.Stream stream = this.generateReportStream(); // todo insert record reference
if(stream)
builder.addAttachment(stream,vendname +" - "+Purchid+".pdf");
var message = builder.getMessage();
SysMailerFactory::getNonInteractiveMailer().sendNonInteractive(message);
}
catch (Exception::Error)
{
throw error("@SYS33567");
}
}
public str Email_Body()
{
str vendname = purchTable::find(this.vendPurchOrderJour.purchid).vendorName();
str Purchid = this.vendPurchOrderJour.purchid;
str sub,tmp,Sender,frm,cc;
[sub,tmp,Sender,frm,cc] = this.getEmailTemplate('POConfirm','en-us');
Esender = sender;
tmp = strReplace(tmp,'%vend%','%1');
tmp = strReplace(tmp,'%purchid%','%2');
str ret = strFmt(tmp,vendname,Purchid);
return ret;
}
public System.IO.MemoryStream generateReportStream()
{
DocuRef addedRecord;
VendPurchOrderJour VendPurchOrderJour = this.vendPurchOrderJour;
Filename fileName = "Report.pdf";
PurchPurchaseOrderController controller = new PurchPurchaseOrderController();
PurchPurchaseOrderContract contract = new PurchPurchaseOrderContract();
SRSPrintDestinationSettings settings;
Array arrayFiles;
System.Byte[] reportBytes = new System.Byte[0]();
SRSProxy srsProxy;
SRSReportRunService srsReportRunService = new SrsReportRunService();
Microsoft.Dynamics.AX.Framework.Reporting.Shared.ReportingService.ParameterValue[] parameterValueArray;
Map reportParametersMap;
SRSReportExecutionInfo executionInfo = new SRSReportExecutionInfo();
System.IO.MemoryStream stream;
Args args = new Args(); ;
args.record(VendPurchOrderJour);
contract.parmRecordId(VendPurchOrderJour.RecId);
controller.parmArgs(args);
controller.parmReportName(ssrsReportStr(PurchPurchaseOrder, Report));
controller.parmShowDialog(false);
controller.parmReportContract().parmRdpContract(contract);
settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::File);
settings.fileName(fileName);
settings.fileFormat(SRSReportFileFormat::PDF);
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());
reportBytes = srsproxy.renderReportToByteArray(controller.parmreportcontract().parmreportpath(),
parameterValueArray,
settings.fileFormat(),
settings.deviceinfo());
if (reportBytes)
{
stream = new System.IO.MemoryStream(reportBytes);
}
return stream;
}
}