Dynamics 365 Finance and Operations (F&O) has the ability to utilize temporary tables in code. There are many examples of temporary tables in the standard application. However, sometimes there is a requirement to display data in a temporary table in a form, so that the user can make selections or modify the data in the form before the data is processed.
One example in the standard application is when you post sub ledger documents, e.g. purchase or sales orders. The system presents the user with temporary data before the system posts the data and it becomes final.
Below is a simple example of how to populate a temporary table and display it in a simple form. It simply demonstrates the above-mentioned technique of using a temporary table as a dataSource and does not have any real-world value.
Create a temporary table or use an existing one. Note: The Table Type property of the table must be TempDB. So, if you are using an existing temporary table, make sure the Table Type property is TempDB.
Populate your temporary table with data. Note: The data in your table will be lost when the table buffer goes out of scope.
public class AVTmpTableDataProvider
{
private AVUpdateDataTmpIdRef tmpIdRef; //added here to keep temp table instance alive while there is an object of this class.
public AVUpdateDataTmpIdRef populateTmpTableDemo()
{
for (int j = 0; j < 100; j++)
{
tmpIdRef.Id = j;
tmpIdRef.Name = guid2Str(newGuid());
tmpIdRef.insert();
}
return tmpIdRef;
}
}
Create a form and add your temporary table as the dataSource. Set the dataSource property of the grid and add some fields to the grid.
In your form, in the dataSource init method, populate your temporary table and then call the linkPhysicalTableInstance method of the dataSource. Note: You have to call this method after the dataSource has been initialized.
[Form]
public class AVTmpTableDialog extends FormRun
{
//form class with an instance of our temp table. added here to keep temp table instance alive while the form is open.
private AVTmpTableDataProvider dataProvider = new AVTmpTableDataProvider();
[DataSource]
class AVUpdateDataTmpIdRef
{
public void init()
{
super();
//populate temp table in form class and link it to this datasource (after datasource has initialized).
AVUpdateDataTmpIdRef.linkPhysicalTableInstance(dataProvider.populateTmpTableDemo());
}
}
}
No comments:
Post a Comment