March 19, 2015

X++ code to mail Report in AX 2012

public void EmailReport(Args _args)
{
    SrsReportRunController controller = new SrsReportRunController();
    SRSPrintDestinationSettings printSettings;
    SrsReportEMailDataContract emailContract;

    // set report name
    controller.parmReportName(ssrsReportStr(CustTransList, Report));

    // create email contract
    emailContract = new SrsReportEMailDataContract();

    // fill in the email contract details
    emailContract.parmAttachmentFileFormat(SRSReportFileFormat::PDF);
    emailContract.parmSubject("Customer Transaction Report");
    emailContract.parmTo("shwethakodli@outlook.com");

    // get print settings from contract
    printSettings = controller.parmReportContract().parmPrintSettings();

    // update print settings with email contract and use pdf format in the attachment
    printSettings.printMediumType(SRSPrintMediumType::Email);
    printSettings.parmEMailContract(emailContract);
    printSettings.fileFormat(SRSReportFileFormat::PDF);

    // suppress the parameter dialog
    controller.parmShowDialog(false);

    // start operation
    controller.startOperation();
    info("Report Mailed");
}

No comments:

Post a Comment