Betta
Betta

Reputation: 13

How to pass argument from one form to another form in ax 2012

Table has one date field. I have two form name as formA and formB ,formA has textbox and button. formB has grid with date field.

So my question is if I enter date in textbox and clicked the button of formA, entered date should be assign in grid of formB. I added table datasource of both forms. Please help me out on this.

Upvotes: 1

Views: 9206

Answers (2)

zadorski
zadorski

Reputation: 71

Although behavior described by you seems to be not so standard in terms of AX, I would suggest you to use dialog form as a FormA (rather than regular form). That way you respect best practices and desired behavior is achieved easier.

Create class extending RunBase class with date field:

class FormADialog extends RunBase
{
    DialogField fieldDate; 
    TransDate   transDate;
}

Here is how we construct form controls:

protected Object Dialog()
{
    Dialog dialog = super();
    fieldDate = dialog.addField(extendedTypeStr(TransDate), 'Date');
    return dialog;
}

The following method will retrieve values from Dialog:

public boolean getFromDialog()
{
    transDate = fieldDate.value();
    return super();
}

Processing logic goes here:

public void run()
{
    FormBTable formBTable;

    ttsbegin;

    select firstOnly forUpdate formBTable;
    formBTable.Date = transDate;
    formBTable.write();

    ttscommit;
}

The only missing thing is entry point for dialog class (represents FormA):

public static void main(Args _args)
{        
    FormADialog     formADialog = new FormADialog();
    FormDataSource  formDataSource;

    if (formADialog.prompt())
    {
        formADialog.run();

        // FormB should contain menu item for dialog class for the following code
        if (args && args.record() && args.record().dataSource())
        {
            formDataSource =  args.record().dataSource();
            formDataSource.research();
        }
    }
}

Now clicking on dialog button will update grid.

If you insist on use of approach with two regular forms. I will think of linkActive() method at the datasource of the second form. Take a look at Tutorial Form Dynalink. A record change in the parent form notifies the child form, making it call the linkActive method which in turn calls the executeQuery method at the child table datasource.

Upvotes: 1

zadorski
zadorski

Reputation: 71

Another approach could be as follows.

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

Initiator form prepares data for transfer within clicked() method of button control:

void clicked() 
{
   Args            args;
   FormRun         formRun;

   args = new Args();
   args.parm(dateField.text());       
   args.name(formStr(FormB));

   formRun = classFactory.formRunClass(args);
   formRun.init();
   formRun.run();
   formRun.wait();

   super();
}

Receiving endpoint should listen at init() method of FormB:

public void init() 
{
   Date passedValue;

   super();              

   // check presence
   if (element.args())
   {
       passedValue = str2Date(element.args().parm(), 123);
   }
} 

Take a look at axaptapedia.com article to see how we can pass complex set of parameters within custom made class.

Upvotes: 0

Related Questions