Passing Multiple Records from one form to another through Args in Dynamics Ax 2012

In my last post, i posted on how to pass Record from one Form to another Form. Now i will pass multiple Record from one Form to another through Args.


The Scenario is when I select multiple grids in Form A, those records will be passed to FormB and there FormB will received the all those records 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.
step 4: Make one Display menuitem of FormB.


void clicked()
{

int recordsCount;
SampleTable _sampleTable;
container con;
Args args;
str multiSelectString;
;

args = new Args();
recordsCount = SampleTable_ds.recordsMarked().lastIndex(); // gets the total records selected
_sampleTable = SampleTable_ds.getFirst(1);

while (_sampleTable)
{
// storing recid of selected field in container
con = conIns(con,1,_sampleTable.RecId);

// converting container to string with comma separated
multiSelectString = con2Str(con,’,’);

_sampleTable = SampleTable_ds.getNext(); // moves to next record
}
// passing string
args.parm(multiSelectString);
// calling menu item
new MenuFunction(menuitemDisplayStr(FormBMenuItem), MenuItemType::Display).run(args);
}


first

step 5: 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 7: write the following code in to the init method of FormB.


public void init()
{
container con;
int i;
str multipleRecords;
super();
// getting string value from caller
multipleRecords = element.args().parm();

// string to container
con = str2con(multipleRecords,”,”);

// for sorting
for(i = 1;i<= conLen(con) ;i++)
{
SampleTbl_ds.query().dataSourceTable(Tablenum(SampleTbl)).addRange(fieldNum(SampleTbl,RecId)).value(SysQuery::value(conPeek(con,i)));
}

}
Please select button property multiselect to “yes

thanks and your feedback will be appreciated.

15 responses

  1. Pls write article on multiple records from form to report as you have written on passing multiple records from from to class
    thanks in advance
    Aditya Negi

    Like

  2. HI Raziq, it was very helpful to me…

    but how to do with different datasources,,,,??can u help me with that…

    Regards,
    Alonso

    Like

    1. Hi Alonso,
      Did you find out how to do with different datasources?
      I have same request

      Like

      1. follow dis example……
        1.write in formB init method >>formb>>methods>>init

        public void init()
        {

        container con;
        int i;real j;

        str multipleRecords;
        LT11AssetEnquirySystemTable enquiry;
        LT11AssetDisplayTable enquiryTMP;
        super();
        multipleRecords = element.args().parm();
        con = str2con(multipleRecords,’,’);
        for(i = 1;i>clicked method

        void clicked()
        {

        int recordsCount;
        LT11AssetEnquirySystemTable ast;
        container con;
        Args args;
        str multiSelectString;

        args = new Args();
        recordsCount = LT11AssetEnquirySystemTable_ds.recordsMarked().lastIndex();
        ast = LT11AssetEnquirySystemTable_ds.getFirst(1);
        while(ast)
        {
        con = conIns(con,1,ast.RecId);
        multiSelectString = con2Str(con,’,’);
        ast = LT11AssetEnquirySystemTable_ds.getNext();
        }
        args.parm(multiSelectString);
        new MenuFunction(menuitemDisplayStr(LT11AssetDisplayTableForm),MenuItemType::Display).run(args);

        }

        Like

    2. 1.write in formB init method >>formb>>methods>>init

      public void init()
      {

      container con;
      int i;real j;

      str multipleRecords;
      LT11AssetEnquirySystemTable enquiry;
      LT11AssetDisplayTable enquiryTMP;
      super();
      multipleRecords = element.args().parm();
      con = str2con(multipleRecords,’,’);
      for(i = 1;i>clicked method

      void clicked()
      {

      int recordsCount;
      LT11AssetEnquirySystemTable ast;
      container con;
      Args args;
      str multiSelectString;

      args = new Args();
      recordsCount = LT11AssetEnquirySystemTable_ds.recordsMarked().lastIndex();
      ast = LT11AssetEnquirySystemTable_ds.getFirst(1);
      while(ast)
      {
      con = conIns(con,1,ast.RecId);
      multiSelectString = con2Str(con,’,’);
      ast = LT11AssetEnquirySystemTable_ds.getNext();
      }
      args.parm(multiSelectString);
      new MenuFunction(menuitemDisplayStr(LT11AssetDisplayTableForm),MenuItemType::Display).run(args);

      }

      Like

  3. I would not suggest changing the container to String, as string has several limitations. Instead, I would use parmObject method, as it is done here :
    http://daynamicsaxaptatutorials.blogspot.in/2011/10/parmobject-with-containerargscontainer.html

    Like

    1. Hi saurah,

      you are correct but this is just for demo on Args, So, I want it to be more simpler.
      Using parmObject method of Args Class is more recommendable.

      Like

  4. Thanks Raziq for the usefull information.. its helps me to explore more on Args.

    Like

  5. When i am selecting 2 records, the button went to visible. What’s the problem for that . Can you please tell me.

    Like

    1. Hi Vijaya,

      What’s exactly your problem is, I didn’t get you. Please be clear on your question.
      until you won’t select multiple grids, there is no mean in visibility of button.

      Hope you understood.

      Happy DaXing……….

      Like

  6. change the property of the button “multiselection” to “YES”

    Like

  7. Hi Raziq,
    I’m trying to pass line values from SO lines to custFreeInvoice lines. Can you guide me how to correctly do that? because these 2 forms have some same fields but different datasources.
    I’m trying to pass Lines with container

    Liked by 1 person

  8. Hi, what to do if we have different datasoure tables in both forms. For example, I have one form with CustInvoiceJour and second form with CustInvoiceTrans. Form A has fields on grid from its datasource and Form B has fields from its datasource. I have drop down on top of the form. Below it, there is a button. I will select a SalesId from the drop down and click on button. Upon clicking, the second form should be opened and show the records of invoice lines on the basis of the Id selected in the first form through drop down.

    Like

Leave a comment