Search code examples
formsaxaptatemp-tablesdynamics-ax-2012x++

How to insert the second record in a Temp Table?


In my form I used a Temporary Table in DataSource - with property TableType: InMemory .

In My form I have a simple code,like this:

public TableTmpTable insertRecords(String _param_I, string _param_II)
{ 
  TableTmpTable myInMemoryTable;

  myInMemoryTable.clear();
  myInMemoryTable.initValue();

  myInMemoryTable.Field_I =  _param_I;
  myInMemoryTable.Field_II = _param_II;

  myInMemoryTable.insert();

  return myInMemoryTable;
}

I need to call this method more than once.

But, whenI call the method I lost my previous record. How can insert more record in InMemory table in different time?

Thanks in advice!


Solution

  • Scope

    An InMemory table is instantiated when the first record is inserted. The instantiated InMemory table continues to exist only while a record buffer variable that references the table exists. The memory or disk space for the InMemory table is de-allocated as soon as the record buffer goes out of scope.

    From MSDN, Temporary InMemory Tables

    What your code does is it creates a new instance of the table buffer each time the method is called. Instead, you need to use the table buffer of the form data source.

    See also Temporary table as form data source and AX 2012: Using Temporary Table as Form’s Datasource