Axaptapedia is now maintained by AgileCadence For more information please click here.


From Axaptapedia
Jump to: navigation, search

The RunBaseReport class is part of the RunBase Framework. Its main purpose is to provide a user interface before the report starts and pack business logic. The RunBaseReport class addresses the issue that there is no inheritence for reports in Dynamics AX. But Dynamics AX supports inheritence for classes. So you can pack business logic in a RunBaseReport class and reuse it for serval reports.

Runbasereport dev.png

Class Methods[edit]

The RunBaseReport class has a lot of methods to define and change the behaviour. Create a new class and extend the RunBaseReport class. At least two methods have to be changed to make the class work

  • main
  • lastValueElementName

The main method makes the class runable from an action menu item. The lastValueElementName returns the name of the report to be started. The framework uses the query from the report <xpp> public static void main(Args _args) {

 ReportDemo demo = new ReportDemo();

} </xpp>

<xpp> public identifiername lastValueElementName() {

 return reportstr(MyReport);

} </xpp>

The RunBaseReport supports user interaction. To provide a user interface and process user input it is necessary to override four methods

  • ClassDeclaration
  • dialog
  • getFromDialog
  • Parameter method

Define a property field in the class declaration and a DialogField element in the class declaration. <xpp> class ReportDemo extends RunBaseReport {

 NoYes       showSum;
 DialogField fieldShowSum;

} </xpp>

The dialog class modifies the default dialog by adding a dialog field <xpp> public Object dialog(DialogRunbase dialog, boolean forceOnClient) {

 Dialog dlg;
 dlg = super(dialog, forceOnClient);
 fieldShowSum = dlg.addField(typeId(NoYes),"Show sum total");
 return dlg;

} </xpp>

The dialog field contains the selected value. The getFromDialog method is used to get the selected value and set the property value. The example is trivial but there may be situations where you have to do some logic to transform user selection in usefull property values. <xpp> public boolean getFromDialog() {

 boolean ret;
 ret = super();
 showSum = fieldShowSum.value();
 return ret;

} </xpp>

All class fields in Dynamics AX cannot be accessed from outside. Create a parameter method to make the field readable

<xpp> // Show sum total field on report public NoYes parmShowSum() {

 return showSum;

} </xpp>

After this modifications the class will look like this

Runbasereport demo1.png

Report Methods[edit]

After pressing the OK button the report starts. The report can determine who called it and make use of the RunBaseReport class and its properties. Do use the class from the report declare a object reference in the class declaration and change the init method

<xpp> public class ReportRun extends ObjectRun {

 ReportDemo demo;

} </xpp>

<xpp> public void init() {

 if(element.args() && element.args().caller() &&
    classIdGet(element.args().caller()) == classNum(ReportDemo))
   demo = element.args().caller();
   throw error("Report must be called using ReportDemo");

} </xpp>