Thursday, May 7, 2015

Passing Records from one Form to another Form in dynamics Ax 2012

Hi every one today I am going to publish "Passing the record from one form to another from using Args In AX 2012R3".

Step1_ first create TableA with fields as Name, Number, City.
Step2_ Create a from as SampleFormA, using data source TableA, then in design take Grid and  BUTTON. In button clicked write this below code 
void clicked()
{   Args args;
    FormRun formRun;
    super();
    args = new args(formStr(SampleFormC));
    args.record(SampleTable2);
    formrun = classFactory.formRunClass(args);
    formRun.init();
    formRun.run();
    formRun.wait();
}

drag and drop the fields to From Grid.

Step3 _ Create Another TableB and SampleFormC , same as above except button and clicked method (No Button and clicked method)

Step4_ In SampleFormC , drag and field to grid , then override form init method, write below code

public void init()
{
    super();
    sampleTable2 = element.args().record();
    this.insertSampleTable3();
   // record filter
    sampleTable3_ds.query().dataSourceTable(Tablenum(sampleTable3)).addRange(fieldNum(sampleTable3,Name)).
    value(SysQuery::value(sampleTable2.Name));

    }
Step5_ Then write insert method in SampleFromC  below code
private void insertSampleTable3()
{
    sampleTable3Loc.Name           = sampleTable2.Name;
    sampleTable3Loc.Number         = SampleTable2.Number;
    sampleTable3Loc.AddressCity    = sampleTable2.AddressCity;

    sampleTable3Loc.insert();
}

Step6_ Declaration in SampleFromC
 public class FormRun extends ObjectRun
{
    sampleTable3    sampleTable3Loc;
    SampleTable2    sampleTable2;
    QueryBuildRange qbrName;
}

Note : This below code is shows only for same record
// record filter
 sampleTable3_ds.query().dataSourceTable(Tablenum(sampleTable3)).addRange(fieldNum(sampleTable3,Name)).
    value(SysQuery::value(sampleTable2.Name));


____ Thank you.