Open form on button click and passing arguements in ax 2012

Description:-

In this article we will see about how to pass arg, parameter, query and array object in one form through another while clicking on button.

Here is the sample code I have written form opening form and passing multiple arguments in another form.
From-1(on button click event)
void clicked()
{
    FormRun formRun;
    Args    args = new Args();
    str         multiSelectString;
    container   con;
    super();
    con = conIns(con,1, InventTrans.ItemId);
    con = conIns(con,2, InventTransOriginMovement.ReferenceId);
    con = conIns(con,3, _RecId);

    multiSelectString = con2Str(con,',');

    args.name(formstr(Display Menuitem));
    args.caller(this);
    args.parm(multiSelectString);
    args.record(DataSource name);
    args.parmObject(new Query(Pass Query));
    formRun = classfactory.formRunClass(args);
    formRun.init();
    formRun.run();
    formRun.wait();
    formRun.detach();
}

In another form Form-2 check for DataSource what DataSource we are getting from form-1. Here I have override form init method for checking Which table we are getting from Form-1. Also you can check in DataSource init method. Like below.
public void init()
{
    //if not from InventDim dataset
    if( element.args().dataset() == tableNum(InventDim))
    {
        super();
    }
    //if directly open
    if(!element.args().caller())
    {
        throw error("Cannot Run Directly.");
    }
}

In DataSource init method you can get those arguments which you are passing in Form-1. Like below.

//dataset start
    if(element.args().dataset())
    {
        //parmObject start
        if(element.args().parmObject())
        {
            ObjInventDim1 = element.args().record();
            //Getting multipleRecords Value start
            multipleRecords = element.args().parm();
            con = str2con(multipleRecords,",");
            for(i1 = 1;i1<= conLen(con) ;i1++)
            {
                if(i1==1){_ItemId = conPeek(con,i1);}
                if(i1==2){_SalesId = conPeek(con,i1);}
                if(i1==3){_RecId = conPeek(con,i1);}
            }
            //Getting multipleRecords Value end

            query1 = new Query(element.args().parmObject());
            Arrays = element.args().parmObject();
}
//parmObject end
    }
//dataset end

Related Posts

Previous
Next Post »

Thanks for comments.....