How to use Temp table as data source of form in AX 2012

Yes, you can use temporary table as datasource whether it is of type tempDb or InMemory.

I assumed that you have temporary table ready and just need to drag in to the form datasource.

Now, Create one method named insertRecords at form level.

eg.,

TmpTable insertRecords()
{

TmpTable tmpTableBuffer;
OtherTable otherTableBuffer;

while tmpTableBuffer
{
tmpTableBuffer.field1 = otherTableBuffer.field1;
.
.
.
.
.
tmpTableBuffer.fieldn = otherTableBuffer.fieldn;
tmpTableBuffer.insert();
}

Now, call this method in init method of form after super.

public void init()
{

super();

// important thing comes here
// if table is of type InMemory,call following method.

TmpTable.setTmpData(element.insertRecords());

// if table is of type tempDb, call following method.

TmpTable.linkPhysicalTableInstance(element.insertRecords());
}

Please let me know if you have any queries.

Happy Daxing…….

Advertisements

3 responses

  1. approach but I get a compiler error saying “Variable TmpTable has not been declared”

    Like

  2. Sorry, on the above example, I realized that TmpTable is actually the name of the DataSource on the Form and not your temporary table type. That worked, thanks!

    Liked by 1 person

    1. You are welcome.

      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

%d bloggers like this: