Make Report at runtime using X++ code in Ax 2009

CODE

static void MakeReportAtRuntime(Args _args)
{
#AOT

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

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

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

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));
section.addDateControl(tablenum(CustTable),fieldnum(CustTable,createdDateTime)).label(“GV_DateA”);
section.labelTopMargin(20.00,Units::mm);
section.topMargin(5.00,Units::mm);
section.leftMargin(10.00,Units::mm);
//Now the report will not prompt for user input
areport.interactive(false);
areport.query().interactive(false);
areport.AOTcompile();

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s