Press ESC to close

How to use RecordInsertList in D365FO

The RecordInsertList class facilitates array insertion functionality within the kernel. This feature enables the simultaneous insertion of multiple records into the database, thereby minimizing communication overhead between the application and the database.  

When iterating through a while loop, it’s optional to insert each record individually and hit the database while inserting every single iteration. An alternative and efficient approach is to utilize RecordInsertList because It will minimize the number of hits to the database. It can speed up your performance of insertion. The following example uses the RecordInsertList class to insert the customer records in the temporary table.  

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;