How to pass a parameter between two forms in Axapta?

后端 未结 1 1301
野性不改
野性不改 2021-01-12 14:39

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

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-12 14:46

    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

    0 讨论(0)
提交回复
热议问题