D365F&O - X++ - Insert records in database using recordInsertList

public void insertCustRecords(CustStatementDirTmp _custStatementDirTmp, Query _userQueryPacked)
{
        CustTable               cust;
        QueryBuildDataSource    dataSource;
        QueryRun                partyRun;
        Query                   Query = new Query(_userQueryPacked);
        RecordInsertList        recordInsertList;
   
        partyQuery.allowCrossCompany(false);
   
        dataSource = partyQuery.dataSourceTable(tableNum(CustTable));
   
        partyRun = new QueryRun(partyQuery);
   
        recordInsertList = new RecordInsertList(_custStatementDirTmp.TableId, false, false, false, false, true, _custStatementDirTmp);
   
        // Add customer parties in current company
        while (partyRun.next())
        {
            cust = partyRun.get(tableNum(CustTable));
   
            _custStatementDirTmp.clear();
            _custStatementDirTmp.Party = cust.Party;
            _custStatementDirTmp.CustCompany = cust.DataAreaId;
            _custStatementDirTmp.CustRecId = cust.RecId;
            recordInsertList.add(_custStatementDirTmp);
        }
        recordInsertList.insertDatabase();
}

Comments

Popular posts from this blog

D365F&O - X++ - Best Practice Warning BP Rule: [BPErrorUnknownLabel]: Path:

D365F&O - X++ - How to Enable/Disable button on form based on a condition in D365F&O using Event handlers.

D365FO - X++ - Generate CAR (Customized Analysis Report) report of custom model