Pass the value from one form to another

Hi guys…

i want to pass the values from one form to another form. and in 2nd form data should come by filtering according to passed values.

Ex.

there is two form

formA and formB

if formA pass twp values to FormB like var1, var2,

so i want that formB data shoud come accoring to var1 and var2.

if anyone knows the answer plz help…

For passing parameters from one form to another a special class Args is usually used.

Example:

The code of button click event of FormA which calls FormB and passes some parameters to that form.

void clicked()
{
    // Args class is usually used in Axapta for passing parameters between forms
    Args            args;
    FormRun         formRun;
    // Our custom made class for passing complex set of parameters
    FormBParams     formBParams = new FormBParams();
    Array           items = new Array( Types::String );
    int         i;
    ;
 
    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( strValue.text() );
    // We also can pass enum value to FormB
    args.parmEnum( NoYesEnumValue.selection() );
    args.parmEnumType( EnumNum( NoYes ) );
    // and also can pass a cursor pointing to some record (in our case it is EmplTable )
    args.record( EmplTable );
 
    // If we want pass more complex set of parameters we can develop our own class
    // just for passing our parameters.
    formBParams.parmSomeDate( someDate.dateValue() );
    formBParams.parmSomeTime( someTime.value() );
    for( i=0; i<ListBox.items(); i++ )
    {
        items.value( i+1,  ListBox.getText( i ) );
    }
    formBParams.parmItems( items );
    // Pass our object to FormB
    args.parmObject( formBParams );
 
    // Run FormB
    args.name( formstr( FormB ) );
    formRun = classFactory.formRunClass( Args );
    formRun.init();
    formrun.run();
    formrun.wait();
 
    if( formrun.closedOk() )
    {
        answerFromFormB.text( args.parm() );
    }
    super();
}

The code of init method of FormB

public void init()
{
    EmplTable       emplTableRecord;
    FormBParams     formBParams;
    Array           items;
    int             i;
    ;
    super();
 
    // Check for passed arguments
    if( element.args() )
    {
        // get string parameter
        strValue.text( element.args().parm() );
 
        // get enum parameter
        if( element.args().parmEnumType() == EnumNum( NoYes ) )
        {
            NoYesEnumValue.selection( element.args().parmEnum() );
        }
        // get object parameter
        if( element.args().parmObject() )
        {
            formBParams = element.args().parmObject();
            items       = formBParams.parmItems();
            for( i=1; i<=items.lastIndex(); i++ )
            {
                ListBox.add( items.value(i) );
            }
            someDate.dateValue( formBParams.parmSomeDate() );
            someTime.value( formBParams.parmSomeTime() );
        }
        // get record parameter
        if( element.args().record() && element.args().record().TableId == TableNum( EmplTable ) )
        {
            emplTableRecord =  element.args().record();
            emplName.text( emplTableRecord.Name );
        }
    }
}

The code of ok button click event of FromB

void clicked()
{
    super();
    element.args().parm( strAnswer.text() );
    element.closeOk();
}

Hey… Thanks for reply…

this code i already tried but its not working… do you know any simple way to do it.

hi try this way;

form A

clicked method

void clicked()

{

Args args;

args = new args();

args.parm( strValue.text() );

}

form B

public void init()

{

if( element.args() )
{
// get string parameter
strValue.text( element.args().parm() );

}

//Now u have the value of var1 after this u can filter u r form datasource using the following code

this.query().dataSourceName(‘datasourceName’).addRange(fieldNum(datasourceTableName, yourDateField)).value(Var1));

}

Hi Deepak,

Is your query resolved ?

Or are you still waiting for some simpler example to understand.

Let me know if you are looking for one … OK !

Regards,

Muneeb

Dear Munneb,

Can you please send some other example to understand.

Thanks,

Hi Guys,

Let me try my hand in providing the solution. Here is my approach.

Lets say we have two forms Form1 and Form2 and Form1 is supposed to send four values irrespective of their datatype to Form2. I want to send the values when a button is clicked and I am using clicked under that button.

  1. In Form1(Send)
    void clicked()
    {
    Args args = new Args();
    ContainerClass conClass_Obj;
    Container conSend;
    ;

conSend = conins(conSend, 1, “Call Of Duty”);
conSend = conins(conSend, 2,“BattleField”);
conSend = conins(conSend, 3, “Assisins Creed”);
conSend = conins(conSend, 4, “retrive hell”);
conClass_Obj = new ContainerClass(conSend);
Args.parmObject(conClass_Obj);
new MenuFunction(menuitemdisplaystr(menuitem_Form2), MenuItemType::Display).run(args);
}

  1. Receive(In Form2)
    public void init()
    {
    //super();
    str s1,s2,s3,s4;
    containerClass conClass_Obj;
    container conRec;
    Args args;
    ;
    super();
    args = new args();
    conClass_Obj = element.args().parmObject();
    conRec = conClass_Obj.value();
    s1 = conpeek(conRec,1);
    s2 = conpeek(conRec,2);
    s3 = conpeek(conRec,3);
    s4 = conpeek(conRec,4);
    info(strfmt(“Value1 = %1 , Value2 = %2 , Value3 = %3 ,Value4 = %4”,s1,s2,s3,s4));
    }

You guys can even use different datatype values and put them in the container and convert it to a object and send it to other form or a report.

Hope this approach helps.

Hi
I want to insert the records from Form A to form B how can i do that?

Are the data source in Form A and Form B are different? Please provide more details.
Feel free to create a new thread.

Dear Chiranjeevi,

I am new to Ax, thanks for the above code, the code works fine for me,

I need bit more help on this. when i am displaying,

  1. Is it possible to display custom fields also here ?

  2. How to enable maximize button,

your immediate help will help me… Please…

Thanks

Ram