Reports to Email from X++

Share on facebook
Share on twitter
Share on linkedin

Many of us may be in need to share Reports directly to Email.

Dynamics 365 for Operations uses SSRS to execute reports (same as AX 2012). Bellow is a runnable class example that will help you implement what you need.

For the Example below consider you have a Customer report that uses a dataset based on CustTable:

class ReportToEmailExampleRunnableClass  

    public static void main(Args _args)

        Map                             queryContracts;
        MapEnumerator                   meQueryContracts;
        Query                           currentQuery;
        QueryBuildDataSource            dataSource;
        SrsReportDataContract           contract;

        SrsReportRunController controller = new SrsReportRunController();
        SRSPrintDestinationSettings printSettings;
        SrsReportEMailDataContract emailContract;

        // set report name
        controller.parmReportName(ssrsReportStr(TestCustomReport, PrecisionDesign1));

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

        // fill in the email contract details
        emailContract.parmSubject("Test Report");
        emailContract.parmTo("[email protected]");

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

        // update print settings with email contract and use pdf format in the attachment

        // suppress the parameter dialog

        // Set any required parameter values here by first getting the report contract.
        contract = controller.parmReportContract();
        // Retrieve the query map and set dynamic parameter values
        queryContracts = contract.parmQueryContracts();
            meQueryContracts = queryContracts.getEnumerator();
                currentQuery = meQueryContracts.currentValue();
         // Set the datasource for query parameter
                dataSource = currentQuery.dataSourceName("CustTable");
                    SysQuery::findOrCreateRange(dataSource,fieldNum(CustTable, AccountNum))


        // start operation



Articles used for reference:

AX 2012 – How To: Directing Reports to Email

Dynamics community – SRSReportServerWarmup – Setting dynamic parameter value(s)

Leave a comment

Fill in your details and we’ll be in touch​