Saturday, January 5, 2019

Passing parameter between forms in Dynamics AX

How to: Pass Args from one form to another form in AX 2012

Passing parameter from one form to another is easy in AX and this concept help a lot during development and it can be achieved through Args class.
I am going to demonstrate below simple example to understand how Args works and what are the different options available in dynamics AX.

Form1: POCVehicleForm
Form2: POCInsuranceMaster  
And there is one common field vehicleId in both data source.
Task1: Pass record, string value and enum value from Form1 to Form2.
Task2: Filter data on form 2 according to the vehicle Id from form one.
Solution: Added one button on the POCVehicleForm to pass value on POCInsuranceMaster form.
Add below code snippet on "Insurance Master" clicked method on POCVehicleForm .
void clicked()
    MenuFunction        mf;
    Args                args;
    FormRun             formRun;
    //Initialise Args
    args= new Args();

    //Pass record

    //Pass string value "Vehicle Id"
    //Pass Enam value

    //Pass enum type


Add below code snippet on POCInsurance’s init method.
public void init()
    POCVehicle              pocVehicle;
    Query                   query;

    // Get record buffer

    // Validate if parameter is not null and record belong to right table  
    if(element.args() && element.args().record().TableId== tableNum(POCVehicle))

    // Filter data according to the Vehicle ID    POCInsurenceMaster_ds.query().dataSourceName('POCInsurenceMaster').addRange(fieldNum(PO  CInsurenceMaster,vehicleID)).value(SysQuery::value(pocVehicle.VehicleId));

     // Show String and enum value                 
    info(strfmt("PARM:%1,PARMENUM:%2)", element.args().parm(),element.args().parmEnum()));  


Below is the result after clicking on Insurance Master button on POCVehicleForm

Below is the Args important methods:

Args Methods Details
record Get and set current or multiple record from caller table
caller Get or set the instance of the caller object
parm Get or sets string value including string field on caller form
parmEnum Get or set enum value
name Get and set the name of the application object to call
parmObject Get or set an instance of any object to pass on called object like any custom class 
parmEnumType Get or set enum name

1 comment: