Make axapta x++ report at runtime

Hi, everybody!

Today, I want to share you an easy way to make a Dynamics AX report at runtime. 

With that, we can to create and modify our reports dynamically, and adjust its properties at runtime.

Code is as follows:

static void MakeReportAtRuntime(Args _args)

    str                     reportName  = 'MakeReport';
    tableid                 custTableId = tablenum(CustTable);
    TreeNode                reportNode  = TreeNode::findNode(#ReportsPath);
    Report                  areport;
    ReportDesign            design;
    ReportAutoDesignSpecs   specs;
    ReportSection           section;
    ReportRun               run;

    //Delete the report if it already exists
    areport = reportNode.AOTfindChild(reportName);
    if (areport)

    //Build the report
    areport = reportNode.AOTadd(reportName);

    design  = areport.addDesign('Design');
    specs   = design.autoDesignSpecs();
    section = specs.addSection(ReportBlockType::Body, custTableId);
    section.addControl(custTableId, fieldnum(CustTable, AccountNum));
    section.addControl(custTableId, fieldnum(CustTable, Name));

    //Now the report will not prompt for user input

    //Run the report
    run = ClassFactory.reportRunClass(new Args(reportName));

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.