How can i pass a single parameter between a form in axapta ? I want to run a Form B from a clicked button event in a Form A and pass... for example the customer id ? How can i read it in the destination form, maybe in the init method ? Thanks
The easiest way is to pass current record. Just change button control's DataSource value for Example to CustTable if CustTable is in current Form data sources. Then in destination form init method:
public void init()
{
CustTable cTable;
;
super();
// Check for passed arguments
if( element.args() )
{
// get record parameter
if( element.args().record() && element.args().record().TableId == TableNum( CustTable ) )
{
cTable = element.args().record();
}
}
}
If you still need pass exactly one value .parm() (or more complex object .parmObject() ) you can do this by overiding source form's button control clicked method:
void clicked()
{
// Args class is usually used in Axapta for passing parameters between forms
Args args;
FormRun formRun;
;
args = new args();
// Our values which we want to pass to FormB
// If we want pass just simple string we can use 'parm' method of 'Args' class
args.parm( "anyStringValue" );
// Run FormB
args.name( formstr( FormB ) );
formRun = classFactory.formRunClass( Args );
formRun.init();
formrun.run();
formrun.wait();
super();
}
Then in destination form init:
public void init()
{
str anyStringValueFromCaller;
;
super();
// Check for passed arguments
if( element.args() )
{
// get string parameter
anyStringValueFromCaller = element.args().parm();
}
}
I should definitely would use only the first method and only in special circumstances would go with #2 method with overriding button click method because this is one of default pattern for passing values between forms. More complex example is available at AxaptaPedia.com Passing values between forms