用X++动态创建(生成)报表完整Job演示

static void DynamicsReportX(Args _args)

{
    #AOT
    str reportName = 'tmp_DynamicxReport_'+curUserID();
    tableid custTableId = tablenum(CustTable);
    TreeNode reportNode = TreeNode::findNode(#ReportsPath);
    Report areport;
    ReportDesign design;
    ReportAutoDesignSpecs specs;
    ReportSection section;
    ReportRun run;
    ;
    // 若存在则先删除,为了避免多用户冲突,报表名后加用户ID
    areport = reportNode.AOTfindChild(reportName);
    if (areport)
        areport.AOTdelete();
    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.addControl(custTableId, fieldnum(CustTable, phone));
    areport.interactive(false);
    areport.query().interactive(false);
    areport.AOTcompile();
    run = ClassFactory.reportRunClass(new Args(reportName));
    run.init();
    run.run();
}

原文地址:https://www.cnblogs.com/KobeZhang/p/4858432.html