Using TempDB Tables in AX 2012 Forms
Having temporary tables stored in the tempDB database is a feature new to AX 2012. It isn’t difficult to use temporary tables to populate forms but the steps deviate from using InMemory temporary tables with forms. Given that difference, I thought I would document here how to use tempDB tables as datasources in AX 2012 forms.
1. Create a temporary table with the fields required. In the property sheet for the table set the TableType property to TempDB.
2. Create a class to populate the temporary table. For example, in step #1 create a table named TempDBEXampleTable. Then create a class with a method that populates and returns a populated TempDBExampleTable:
public TempDBExampleTable populateTempTable() { TempDBExampleTable tempTable; int I; for(i = 0;i <= 5; i++) { tempTable.Field1 = "string value"; tempTable.Field2 = i; tempTable.insert(); } return tempTable; }
3. Create a form and add the TempDBExampleTable as the datasource to the form.
4. In the classDeclaration of the form declare an instance of the TempDBExampleTable table. (This step isn’t required but this is how I chose to build my form.)
public class FormRun extends ObjectRun { TempDBExampleTable tempTable; }
5. In the init method of the form datasource instantiate the class you created in step #2.
6. Still in the datasource’s init method, call the method created in step #2 to populate the temporary table and set the class variable equal to what the method returns.
7. Still in the datasource’s init method, from the buffer for the datasource call the linkPhysicalTableInstance method and pass it the populated temporary table returned in step #6. The code for the datasource’s init method should look something like this:
public void init() { ClassBuildingTempTable classBuildingTempTable = new ClassBuildingTempTable(); super(); tempTable = classBuildingTempTable.populateTempTable(); TempDBExampleTable.linkPhysicalTableInstance(tempTable); }
Under the terms of this license, you are authorized to share and redistribute the content across various mediums, subject to adherence to the specified conditions: you must provide proper attribution to Stoneridge as the original creator in a manner that does not imply their endorsement of your use, the material is to be utilized solely for non-commercial purposes, and alterations, modifications, or derivative works based on the original material are strictly prohibited.
Responsibility rests with the licensee to ensure that their use of the material does not violate any other rights.