- Kernel Array Insertion: The
RecordInsertListclass executes bulk array inserts directly into the SQL database engine. - Eliminating Loop Overhead: Prevents issuing individual database round-trips for every iteration of a
while selectloop. - Buffer Management: Accumulates in-memory table records and commits them in optimal packet sizes using
insertDatabase(). - Transaction Boundary Best Practices: Scoping array inserts within clean
ttsbegin/ttscommitblocks. - Temporary & Regular Tables: Equally effective for accelerating SSRS temporary table population and large batch staging tables.
Overview: What is RecordInsertList?
The RecordInsertList class provides array insertion functionality within the Dynamics 365 kernel. When iterating through a while loop or business processing algorithm, inserting each record individually hits the database repeatedly, resulting in severe network latency and transactional overhead.
RecordInsertList buffers records in memory and executes a single bulk SQL insert operation once insertDatabase() is called, dramatically boosting throughput.
“Using RecordInsertList inside batch processing loops reduces database round-trips by over 90%, transforming long-running jobs into streamlined, high-speed operations.”
Complete X++ Code Example
The following sample demonstrates initializing RecordInsertList, queuing records inside a joined query loop, and committing the entire array to the database:
MDTableTmp mdTableTmp;
CustTable custTable;
CustGroup custGroup;
RecordInsertList recordInsertListTmpTable;
recordInsertListTmpTable = new RecordInsertList(tableNum(MDTableTmp),
false,
false,
false,
false,
false,
mdTableTmp);
ttsbegin;
while select AccountNum, Currency, TaxGroup
from custTable
join Name
from custGroup
where custTable.CustGroup == custGroup.CustGroup
&& custGroup.CustGroup == custGroupId
{
mdTableTmp.clear();
mdTableTmp.AccountNum = custTable.AccountNum;
mdTableTmp.Currency = custTable.Currency;
mdTableTmp.TaxGroup = custTable.TaxGroup;
mdTableTmp.Name = custGroup.Name;
recordInsertListTmpTable.add(mdTableTmp);
}
recordInsertListTmpTable.insertDatabase();
ttscommit;
Key Parameters & Performance Rules
- Skip Methods Flags: The
RecordInsertListconstructor accepts boolean flags to bypassinsert(),validateWrite(), and database events when maximum speed is required. - Transaction Scope: Always ensure
recordInsertList.insertDatabase()is called beforettscommitto maintain ACID transactional integrity. - Buffer Reuse: Call
tableBuffer.clear()before setting field values in each iteration to prevent unintended data carry-over.