How to: Pass Args from one form to another form in AX
2012
Below is the Args important methods:
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
args.record(POCVehicle);
//Pass string value "Vehicle Id"
args.parm(Grid_VehicleId.valueStr());
//Pass Enam value
args.parmEnum(VehicleType::Truck);
//Pass enum type
args.parmEnumType(enumNum(VehicleType));
formRun=ClassFactory.formRunClass(args);
formRun.init();
formRun.run();
formRun.wait();
}
Add below code snippet on POCInsurance’s init method.
public void init()
{
POCVehicle pocVehicle;
Query query;
;
super();
// Get record buffer
pocVehicle=element.args().record();
// 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 |
No comments:
Post a Comment