How to pass a parameter between two forms in Axapta?

半世苍凉 提交于 2019-12-01 02:31:25

问题


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


回答1:


1 Method

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();            
        }
    }
}

2 Method

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



来源:https://stackoverflow.com/questions/11258375/how-to-pass-a-parameter-between-two-forms-in-axapta

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!