XPO File: /Files/JackyXu1981/ProdReport.rar
Objective: Develop a complex report by X++ (Axapta or Dynamics AX)
Key point: pass parameter, temporary table, query, programmable report
Steps:
Step 1: Create a table as temporary named myTableTMP.
Step 2: Create a Report named myReport.
Step 3: Create a class to show dialog box.
A, Class Declaration
class myClass extends RunBaseReport
{
DialogField dialogsetsqm;
SETSQM enSetSQM;
}
B, Overwrite dialog()
public Object dialog(DialogRunbase dialog, boolean forceOnClient)
{
Object ret;
ret = super(dialog, forceOnClient);
dialogsetsqm = ret.addFieldValue(Typeid( SetSQM ), SETSQM::SET ,"Please select unit measurement for report");
return ret;
}
C, Overwrite getFromDialog()
public boolean getFromDialog()
{
boolean ret;
ret = super();
enSetSQM = dialogsetsqm.value();
return ret;
}
D, Pass parameter value
SetSQM parmSetSQM (SetSQM _setsqm = enSetSQM)
{
enSetSQM = _setsqm;
return _setsqm;
}
E, Overwrite lastValueElementName()
public identifiername lastValueElementName()
{
identifiername ret;
ret = reportstr(YourReportName);
return ret;
}
F, Define a method as temporary table type as your defination to calculate data and insert the data into temporary table.
Server Static myTableTMP CalculateDate(SETSQM _setsqm)
{
myTableTMP RptData;
;
Delete_from RptData;
if(true)
{
ttsbegin;
RptData.XXX='XXX';
RptData.update();
ttscommit;
}
return RptData;
}
G, Overwrite main()
static void main(Args args)
{
myReport _report = new myReport()
;
if (_report.prompt())
_report.run();
}
Step 4: Report
A, Report class declaration
public class ReportRun extends ObjectRun
{
myReport _clsRpt;
myTableTMP _wcpmonthtable ;
}
B, Overwrite init()
public void init()
{
_clsRpt = element.args().caller() ; // pass the parameter from a class to report
super();
}
C, Overwrite Fetch()
public boolean fetch()
{
boolean ret;
boolean bRunOnce=true;
int ntemp[14];
int i ;
QueryBuildDataSource wcpmonth;
myTableTMP data1,data2 ;
Query q;
QueryRun qr;
str 30 itemgrouparr[] ;
int j=1 ;
;
data1 = myClass::CalculateData(_clsRpt.parmSetSQM()); //Get data calculated from class
myTableTMP.setTmpData(data1); //Setup data to temp table
q = new Query(this); // define query
wcpmonth = q.dataSourceTable(tablenum(myTableTMP)) ; // define query field
SysQuery::findOrCreateRange(wcpmonth, fieldnum(myTableTMP, Blind));
SysQuery::findOrCreateRange(wcpmonth, fieldnum(myTableTMP, Size));
SysQuery::findOrCreateRange(wcpmonth, fieldnum(myTableTMP, Purpose)) ;
if(true) //define query sort order
{
wcpmonth.addSortField(fieldnum(myTableTMP, Purpose),SortOrder::Ascending) ;
}
qr = new QueryRun(q);
qr.setCursor(data1) ; //using data1 to setup cursor for query
//myPurpose = wcpmonth.rangeField(fieldnum(myTableTMP, Purpose)).value() ; // Get query field value
while (qr.next())
{
_wcpmonthtable = qr.get(tablenum(myTableTMP));
this.execute(3) ; // insert programmable part. 3 is a control number on programmable part report
}
element.send(_wcpmonthtable);
return true;
}