GuruGroup logo
X++ High-Performance Engineering

How to use RecordInsertList in D365FO

Executive Summary & Key Architectural Takeaways
  • Kernel Array Insertion: The RecordInsertList class 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 select loop.
  • 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 / ttscommit blocks.
  • 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.”

— Muhammad Hammad, Dynamics 365 Technical Consultant

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 RecordInsertList constructor accepts boolean flags to bypass insert(), validateWrite(), and database events when maximum speed is required.
  • Transaction Scope: Always ensure recordInsertList.insertDatabase() is called before ttscommit to maintain ACID transactional integrity.
  • Buffer Reuse: Call tableBuffer.clear() before setting field values in each iteration to prevent unintended data carry-over.
Ready to Move Forward?

Turn Your Business Goals into Measurable Results

Partner with Guru Group to design, deliver, and scale secure technology solutions for your organization.