How to insert a record directly through query X++


static void test_insertRecordThroughQuery(Args _args)
{
CUSTTEST testTable;
Map fieldMapping;
Query query = new Query();
QueryBuildDataSource qbds_custTable;
QueryBuildFieldList fldList_custTable;

qbds_custTable = query.addDataSource(tableNum(CustTable));

// Field lists are required
// ————————
fldList_custTable = qbds_custTable.fields();
fldList_custTable.addField(fieldNum(CustTable, AccountNum));
fldList_custTable.addField(fieldNum(CustTable, BirthDate_IT));

fldList_custTable.dynamic(QueryFieldListDynamic::No);

fieldMapping = new Map(Types::String, Types::Container);

fieldMapping.insert(fieldStr(testTable, Name), [qbds_custTable.uniqueId(), fieldStr(CustTable, AccountNum)]);
fieldMapping.insert(fieldStr(
testTable, TransDate), [qbds_custTable.uniqueId(), fieldStr(CustTable, BirthDate_IT)]);

// Let AX handle getting data from the query to the target table
// ————————————————————-
query::insert_recordset(
testTable, fieldMapping, query);

info (“Done”);

}

Output:





Comments