Dynamics 365 Business Central: How to check if a record/table is temporary via AL

Dynamics 365 Business Central

Hi, Readers.
Today I would like to share another mini tip about Business Central, how to check if a record/table is temporary in AL.

A temporary table is a temporary variable that holds a table. A temporary table is used as a buffer or intermediate storage for table data.
You can use a temporary table just like you use a database table. The differences between a temporary table and a database table are as follows:

  • A temporary table data isn’t stored in the database. It’s only held in memory until the table is closed.
  • The write transaction principle that applies to a database table doesn’t apply to a temporary table.

More details: Temporary tables

PS: With Business Central 2023 release wave 1 IntelliSense, tooltips, and CodeLens displays a suffix after the table name to indicate when a table is a temporary table. More details: Business Central 2023 wave 1 (BC22): IntelliSense indicator for temporary tables and IntelliSense suggestion for enum ordinal value

The advantage of using a temporary table is that all the interaction with a temporary table occurs on Dynamics 365 Business Central. A temporary table reduces the load on both the network and the SQL database server.
When you want to do many operations on the data in a specific database table, you can load the data into a temporary table when you modify it. Loading the data into a temporary table speeds up the process because all the operations are done in memory on the Business Central Server. When subscribing to events, if it is a temporary table, sometimes you need to skip some processing. A simple example is that you need to insert some custom data when posting, but the user just uses Preview Posting. If you insert data at this time, an error may be prompted or the data may be inserted repeatedly the next time user run Preview Posting (Maybe not a very good example😑).

So can we check if a record/table is temporary via AL? Yes, this is one of the things we need to pay special attention to when customizing. Here’s a standard method.
Record.IsTemporary() Method: Determines whether a record refers to a temporary table.

There are three ways to implement a temporary table. Let’s see a few examples:

1. Using a temporary record variable: With this implementation, a physical table isn’t created in the database. You create a global or local variable of the type record and set the Temporary Property next to it. The variable that holds a temporary table is defined just like any other global or local variable.

We can check by Record.IsTemporary() Method.

2. Setting TableType property of a table to Temporary: With this implementation, a physical table isn’t created in the database.

This implementation has the same effect as using a temporary record variable or setting the SourceTableTemporary property on a page. But the advantage is that the table schema isn’t synchronized with the database. So it doesn’t have restrictions on breaking schema changes, like removing a field, changing its data type or length.

Regardless of whether temporary is added when declaring a variable, it will be considered a temporary table.

3. Using a SourceTableTemporary property on page objects: Another option for temporary tables is to set the SourceTableTemporary on all pages that use the table. This implementation will also use a physical table in the database.

Same as the two above.

Maybe there are some errors that you only notice after you’ve experienced them, please remember that it may be caused by temporary tables. Give it a try!!!😁

1. You can find many similar handlings in the standard. For example,

2. It can also be used for RecordRef Data Type.
RecordRef.IsTemporary() Method: Determines whether a RecordRef refers to a temporary table.


Hope this will help.

Thanks for reading.



Copied title and URL