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

Args concept in dynamics ax is awesome. one can easily pass arguments from one Form to another Form with very less effort. Here, i am going to demonstrate how to pass Arguments from Form to Form. The Scenario is when I select one grid in Form A, that record will be passed to Form B and there Form B will received the whole record and filter it and will show.

Step 1: Make one SampleTable which has three fields named (SIno, name, AddressCity).
Step 2: Make FormA with datasource as SampleTable and drag the datasource fields into the design Grid.
Step 3: Drag one button and override the click method and write the following code.

void clicked()
{
Args args;
FormRun formRun;
;
super();
args = new args(formstr(FormB)); // sending Args(record) to FormB
args.record(SampleTable);
formrun = classfactory.formrunclass(args);
formrun.init();
formrun.run();
formrun.wait();
formrun.detach();

}

first

step 4: Make FormB with datasource as same table for which you take for Form A i.e., SampleTable and drag the fields in to the
Grid of design part.

step 5: write the following code in to the init method of FormB.

public void init()
{
SampleTable _sampleTable;
super();
_sampleTable = element.args().record();
SampleTable_ds.query().dataSourceTable(Tablenum(SampleTable)).addRange(fieldNum(SampleTbl,RecId)).
value(SysQuery::value(_sampleTable.Recid));
}

Note: You can pass only one Record with this Code, if you want to pass multiple grids,i will cover in next post.


thanks and your feedback will be appreciated.

Advertisements

15 responses

  1. Willem van Duren | Reply

    Thank you very much! Works like a charm

    Like

    1. Thanks it helped me..

      Like

  2. HI Raziq, in this scnario i can pass the values from Form A to Form B. but how to store the passing values in form B. Can you reply me.

    Like

  3. Thanks Man .. Very Help Full Since I am New Ax 😉

    Like

  4. Thanks,Worked like a charm..

    Like

  5. Mahesh Khandewal | Reply

    Thanks It worked in first attempt. Good for freshers.

    Like

  6. Can You Please Explain Me SampleTable_ds.query().dataSourceTable(Tablenum(SampleTable)).addRange(fieldNum(SampleTbl,RecId)).
    value(SysQuery::value(_sampleTable.Recid));

    Liked by 1 person

    1. Hi Banu Nk,

      I will explain the same scenario with simple code which is written below.

      To retrieve the only record which is passed through args, you need some key to retrieve i.e., recid (primary key by default).

      Adding the datasource to query with appropriate range which is recid in our case.

      As we received the record through args using following statement below.
      _sampleTable = element.args().record();
      This will be passed as range to the query defined below.
      Query query = new Query();
      QueryRun qr;
      QueryBuildDataSource qbds;
      QueryBuildRange qbr;

      qbds = query.addDataSource(tableNum(SampleTable));
      qbr = qbds.addRange(fieldNum(SampleTable, Recid));
      qbr.value(SysQuery::value(_sampleTable.recid));
      qr = new QueryRun(query);
      SampleTable_ds.query(qr.query());

      Please let me know if you have more queries.
      Happing DaXing……..
      Thanks,

      Raziq

      Like

  7. I have a similar issue but I have form A that opens form B with a button, but then I want to pass a field from form B into form A instead of the other way around.

    Like

  8. Waiting for next post(passing multiple values).Thanks in Advance.

    Liked by 1 person

  9. Great it is useful for me in many task … if u want to pass from listpage see tis link
    http://pravin22ax.blogspot.in/2017/03/argument-passing-from-one-form-to.html

    Like

  10. formrun = classfactory.formrunclass(args); can u plz explain this line of code

    Like

    1. When you want to run Form or report through code, it can only only possible using ClassFactory class. If you want to run Form then formRun method of ClassFactory class and if you want to run Report then reportRun method of ClassFactory class.

      Thanks,
      Raziq

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s