Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

How to send email with sales packing slip report by code

(0) ShareShare
ReportReport
Posted on by 577

I have tried the code below and the sales packing slip report pdf just has the header without content but the content is shown if I print the report on the screen. What is missing in the code?

SysMailerMessageBuilder         mailer = new SysMailerMessageBuilder();
SysMailerSMTP                   smtp = new SysMailerSMTP();

custName = "abc";

mailer.setSubject(strFmt("%1 %2 Packing slip %3", custName, dlvDate, PackingSlipId));
mailer.setFrom("bbb@email.com");
mailer.setBody("fyi");

mailer.addTo("aaa@email.com");

//generate packing slip pdf
//Set  variables
Array                           arrayFiles;
SRSProxy                        srsProxy;
Map                             reportParametersMap;
SRSPrintDestinationSettings     settings;
Filename                        fileName =     strFmt("packing slip %1.pdf", PackingSlipId);
SrsReportRunController          formLetterController = SalesPackingSlipController::construct();
SalesPackingSlipController      controller = formLetterController;
SalesPackingSlipContract        contract = new SalesPackingSlipContract();
System.Byte[]                   reportBytes = new System.Byte[0]();
SRSReportRunService             srsReportRunService = new SrsReportRunService();
SRSReportExecutionInfo          executionInfo = new SRSReportExecutionInfo();

Microsoft.Dynamics.AX.Framework.Reporting.Shared.ReportingService.ParameterValue[] parameterValueArray;

//set the report contract parameters
CustPackingSlipJour custPackingSlipJour;
select custPackingSlipJour
    where custPackingSlipJour.PackingSlipId == PackingSlipId;
contract.parmRecordId(custPackingSlipJour.RecId);
contract.parmTableId(tableNum(CustPackingSlipJour));

//2nd paramter contract.parm2ndtParameter('2ndParamter value');
//3rd parameter
//4th parameter

//set the report controller parameters

//set report name and design name
//controller.parmArgs(_args);
controller.parmReportName(ssrsReportStr(XXX_SalesPackingSlip, Report));
controller.parmShowDialog(false);
controller.parmLoadFromSysLastValue(false);
controller.parmReportContract().parmRdpContract(contract);

// Provide printer settings

settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::File);
settings.fileName(fileName);
settings.fileFormat(SRSReportFileFormat::PDF);

// Below is a part of code responsible for rendering the report

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,
                                settings.fileFormat(),
                                settings.deviceinfo());

if (reportBytes)
{
    System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(reportBytes);
    mailer.addAttachment(memoryStream, fileName, "application/pdf");
}

smtp.sendNonInteractive(mailer.getMessage());

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Jahanvi Profile Picture

Jahanvi 34

#2
PJ JohnPaul Profile Picture

PJ JohnPaul 5

#3
SudhanshuMSID Profile Picture

SudhanshuMSID 1

Overall leaderboard

Product updates

Dynamics 365 release plans