This job try to demonstrate how the SysReportRun class work. And how use AutoSum & AutoHeader parameters.
Settings:
1) Create table "People" with such fields: Surname(str), Salary(EDT-Amount), MyGroup(str)
2) Fill table
Notice:
- Grand total perform only on the fields derived from Amount (from latest build AmountMST also)
- The Print Options dosnt work proper
X++:
static void Job2(Args _args)
{
SysReportRun sysReportRun;
Args args = new Args(reportstr(SysReportAuto));
People people;
SysQueryRun sysQueryRun;
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
Report report;
ReportDesign reportDesign;
ReportAutoDesignSpecs reportAutoDesignSpecs;
ReportSection reportSection;
Object reportControl;
ReportRealControl reportRealControl;
;
//Init reportRun
sysReportRun = classfactory.reportRunClass(args);
sysReportRun.init();
//Setup group total field(s) with autoSum and autoHeader
queryBuildDataSource = query.addDataSource( tablenum(people) );
queryBuildDataSource.addSortField( fieldnum(people, Salary) );
queryBuildDataSource.autoSum(1, true);//Autosum for 1st sort field
queryBuildDataSource.addSortField( fieldnum(people, MyGroup) );
queryBuildDataSource.autoHeader(2, true);//AutoHeader for 2nd sort field
//Init queryRun on reportRun
sysQueryRun = new SysQueryRun( query );
sysQueryRun.promptLoadLastUsedQuery( false );// use created queryRun
sysReportRun.queryRun( sysQueryRun );
//Setup and create repor design
report = sysReportRun.report();
report.query(sysReportRun.queryRun().query());
reportDesign = report.design();
reportDesign.caption( 'Test for people' );
reportDesign.reportTemplate( 'FrontPage' );
reportAutoDesignSpecs = reportDesign.autoDesignSpecs();
// Add section and fields on the report
reportSection = reportAutoDesignSpecs.addSection(ReportBlockType::Body, people.TableId);
reportControl = reportSection.addControl(people.TableId, fieldnum(people, Name));
reportControl = reportSection.addControl(people.TableId, fieldnum(people, MyGroup));
reportControl = reportSection.addControl(people.TableId, fieldnum(people, Salary));
reportRealControl = reportControl; //calculate grand total on this field
reportRealControl.sumAll( true );
reportAutoDesignSpecs.grandTotal( true );
//Block form usage
sysReportRun.queryRun().query().interactive( false );
report.interactive( false );
//Setup print options:
//Print ranges, print totals only, print grand total, remove...repetitive, remove ...identical
sysReportRun.printRemoveRepeatedHeaders(true);
sysReportRun.buildPrintRemoveRepeatedHeaders();
sysReportRun.run();
}