AX – D365FO – How to count affected/updated rows in a Update_recordset statement in X++ Code
Usama Mehmood
Senior Technical Consultant ERP / Microsoft Dynamics 365 Finance & Operations | Integration & Customization specialist | Enabler of Business | Digital Transformation
The X++ SQL statement update_recordset enables you to update multiple rows in a single trip to the server. This means that certain tasks may have improved performance by using the power of the SQL server.
update_recordset resembles?delete_from in X++ and to UPDATE SET in SQL. It works on the database server-side on an SQL-style record set, instead of retrieving each record separately by fetching, changing, and updating.
Example
MyTable myTableBuffer;
;
update_recordset myTableBuffer
setting
field1 = 1,
field2 = fieldX + fieldY
where field1 == 0;
How to count affected/updated rows in a Update_recordset statement
update_recordset inventTable
setting
XXXCommercialGroupId = comunanzaXXX.SubGroupId
join comXXX
where inventTable.ItemId == comXXX.comunanzaCode
&& comXXX.SubGroupId != '';
info(strFmt("Copy Items from comXXX Subgroup Id to InventTable Commercial group Id: %1 rows affected", int2Str(inventTable.RowCount())));
Happy Learning!!