Use Normal Table as Temp Table in Dynamics 365 Finance and Operations

0

Use Normal Table as Temp Table in Dynamics 365 Finance and Operations

Basically, Standard Dynamics 365 Finance and Operation projects contain many temporary tables and regular tables. Imagine a scenario in which you have to create a complex temporary table that is similar to an already existing regular table. In this situation, you can use the existing regular table as a temp table. 

As we already read, InMemory tables are temporary tables that are held in the memory and written to a local disc after reaching a certain limit of the system, especially in an Application Object Server (AOS). So this method saves records on local disc/memory instead of saving them into the database. Also deleting records from the temporary table will not delete anything from the database.

In Microsoft  Dynamics 365 Finance and Operation projects you can use the following coding snippets to convert a regular table to a temp table.

As an example, we will use the vendor table to insert and display a couple of temporary records without affecting actual data. Yo create a Runnable Class named VendTableToTemp 


class VendTableToTemp
{   
  public static void main(Args _args)
 {
      VendTable vendTable;
      vendTable.setTmp();
      vendTable.AccountNum = '1001';
      vendTable.Blocked = CustVendorBlocked::No;
      vendTable.Party =Supplier 1;
      vendTable.doInsert();
      vendTable.clear();
      vendTable.AccountNum = '1002';
      vendTable.Blocked = CustVendorBlocked::All;
      vendTable.Party = Supplier 2;
      vendTable.doInsert();
      while select vendTable
     {
        info(strFmt( "%1 - %2", vendTable.AccountNum, vendTable.Name));
      }
 } 
}

In the code, we first call the setTmp() method on the vendTable table to make it temporary in the scope of this method. This means that any data manipulations will be lost once the execution of this method is over and the actual table content will not be affected.


The key method used here to convert a regular table to a temp table is setTmp(); 
which creates an InMemory Table which has the same structure as that of the original table. setTmp() : has nothing to do with deletion at all. It turns a buffer into a temporary one, therefore it saves records to memory/on disk instead of into the database. If you delete everything from the temporary buffer, it doesn’t delete anything in the database, obviously.

Next, we will use doInsert() to bypass any validation rules which are not required for a temporary table.

We have to keep in mind that even if the table becomes temporary; all the code in its insert(), update(), delete(), initValue(), and other methods are still present and we have to make sure that we don't call it unintentionally.

Post a Comment

0 Comments
Post a Comment
>
To Top