How to use record insert list using X++?
Introduction: If we are inserting a single record, we can use the insert() method. However, if we use the insert() method for bulk insertion, it will make a database call for each record. Instead, we can use RecordInsertList to insert multiple records at once, improving performance by reducing the number of database calls.
Scenario: By using RecordInsertList to insert multiple invoiced sales order records into a custom table, based on the invoiced sales orders from the SalesTable and ensuring better performance when working with large datasets.
High level resolution steps
- Create a runnable class.
- Write the business logics in runnable class.
- Execute the runnable job.
Detailed resolution steps:
Step 1: Create a runnable class and write the below code which is shown in the below screenshot.
Code snippet:

class PRASalesOrderInvoiceInformation
{
///
/// Class entry point. The system will call this method when a designated menu
/// is selected or when execution starts and this class is set as the startup class.
///
/// The specified arguments.
public static void main(Args _args)
{
PRASalesOrderInvoiceInformation praSalesOrderInvoiceInformation = new PRASalesOrderInvoiceInformation();
praSalesOrderInvoiceInformation::getSalesOrderInvoicedInformation();
}
///
/// Loop all the sales order invoiced records and inserting it in custom table.
///
public static void getSalesOrderInvoicedInformation()
{
SalesTable salesTable;
PRASalesOrderInvoiceInformationTable praSalesOrderInvoiceInformationTable;
RecordInsertList recordInsertList = new RecordInsertList(tableNum(PRASalesOrderInvoiceInformationTable));
while select salesTable
where salesTable.SalesStatus == SalesStatus::Invoiced
{
praSalesOrderInvoiceInformationTable = PRASalesOrderInvoiceInformationTable::find(salesTable.SalesId);
if (!praSalesOrderInvoiceInformationTable.SalesId)
{
praSalesOrderInvoiceInformationTable.SalesId = salesTable.SalesId;
praSalesOrderInvoiceInformationTable.SalesName = salesTable.SalesName;
praSalesOrderInvoiceInformationTable.SalesStatus = salesTable.SalesStatus;
praSalesOrderInvoiceInformationTable.InvoiceAccount = salesTable.InvoiceAccount;
recordInsertList.add(praSalesOrderInvoiceInformationTable);
}
}
recordInsertList.insertDatabase();
}
}
Code Explanation:
In this runnable class, looping all the sales order records which is invoiced and inserting multiple records in custom table using record insert list Once the runnable job is executed in Dynamics UI.
Output:
Use the URL below to execute the runnable in the Dynamics UI, as shown in the below screenshot.
URL:
https://usnconeboxax1aos.cloud.onebox.dynamics.com/?cmp=USMF&mi=PRASalesOrderInvoiceInformation

Once the batch job is completed, it will create multiple sales order invoice records in custom table.
