AX 2012 - How to send SSRS report in email as an attachment using X++

Hi Technical,

Today, in this post we will share, how you can send SSRS report in email as an attachment using X++. Please find the below code...

// Created by: Chirag Gupta
// Created date: 17-Sep-19
// Summary: Send SSRS Report in excel format as attachment in email.

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

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

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

    // fill in the email contract details
    emailContract.parmAttachmentFileFormat(SRSReportFileFormat::Excel);
    emailContract.parmSubject("RMPM BPR Report " + strUpr(curext()));
    emailContract.parmBody("Dear Customer, Please find attachment.");
    emailContract.parmTo("axwithchirag@gmail.com");
    emailContract.parmCc("chirag.gupta0123@gmail.com");

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

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

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

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


Comment below if you find this article helpful...

Author:
Chirag Gupta
Microsoft Dynamics 365 AX Technical Consultant at IBM Bangalore

Date:
17-Sep-2019

Happy Learning !!

Comments

Post a Comment

Popular posts from this blog

[Solved] : Error: String or binary data would be truncated. Cannot execute a data definition language command on Vendor (VendLedgerReconciliationTmp)

AX 2012 - Command prompt compilation / AxBuild.exe for Parallel Compile on AOS of X++ to P-code / Parallel Compilation

AX 2012 - How to stop AOS when services got stuck at stopping status

AX 2012 - How to make a form field mandatory

Error: There was no endpoint listening at net.tcp://your_server_name:8201/Dynamics AX/Services…

Fetch vendor address using X++ in AX 2012

AX 2012 - How to print current date and time on SSRS Report

[Solved] : AX 2012 - No connection could be made because the target machine actively refused it 192.168.10.249:8201

[Error] - Error in unit of amount in currency KES. Must be rounded to 0.01 | The unit of 37.563.5343100000000000 KES being posted to account 32710001-- is outside the current penny rounding threshold | Posting has been canceled