AX 2012 Calling Form from a class

I have:

  1. class → performing calculation and select queries based on the date range from the 1st form. Inserts the data in the in-memory table

  2. a in-memory table → stores the calculated fields for that instance

  3. a form.–> Lets call it 2nd form. This should display all the data from the in-memory table

1st Form has a button that should bring up the 2nd form.
The design of what I have right now is…

  1. Where to pass the date ranges to… directly to the class as it has the data calculation method and have the class call the 2nd form ?

  2. class generates the in-memory table.

  3. I can call the class from the ‘2nd form’ and set the ‘setTmp’ method on the form itself to pick the data from the table.
    like:

returnedTmpTable = FormHelperClass.getData(fromDateLocal, toDateLocal);
Form.setTmpData(returnedTmpTable);

  1. How to initiate the form?
    I was thinking of using FormRun to run the Form and pass the parameters(date ranges)…

I am totally unsure about how to proceed further. Any help would be appreciated.

2nd form: Has a grid, and some StringEdits that will calculate based on the data in the grid(in-memory table). More like a SalesLine and SalesLineDetails.


There are many ways how to approach it.

Regarding 1), the button can either call the class which will then call the form, or it can call the form which will then ask the class to do the calculation. If you choose the latter approach, you’ll need something to hold the parameters - I would create one class for parameters (it may even be a data contract) and another class doing the calculation (it may use SysOperation framework).

Regarding 4), if you choose the design when the form is called by a menu item button directly from the first form, you have no problem at all. If you want to execute it from the class, you can either execute the menu item through MenuFunction class, or to create a FormRun instance (classFactory.formRunClass()) and call its methods (init(), run(), wait()/detach).

Thanks for the quick response martin. I follow the FormRun approach. I am writing the solution here as well, in case somebody needs it in the future.

This is for calling the form and passing the params:

args = new Args();
args.name(formStr(Form));
con = conIns(con,1,fromDateLocal);
con = conIns(con,2,toDateLocal);
args.parm(con2Str(con));
formRun = ClassFactory.formRunClass(args);
formRun.init();
formRun.run();
formRun.wait();
formRun.detach();

This is for retrieving the args(in init method):

args = element.args();
// get string parameter
records= args.parm();
con = str2con(records);

Again, thanks very much.

Rather then passing parameters in a string, create a class and pass it through args.parmObject(). It’s object-oriented development, after all. You’ll get simpler code, compile-time control and so on.

Also, use either FormRun.wait() (if you want to stop execution until the form is closed) or FormRun.detach() (if you want not to wait for the form), not both.

Thanks for both of the advises. Thanks very much.