class VKDataFix651 { /// <summary> /// Deleting odd transaction, which left from work which is not longer available in the system. /// </summary> /// <param name = "_args">The specified arguments.</param> public static void main(Args _args) { InventTransOrigin inventTransOrigin; InventTransRefId workId = 'WRK086211'; ItemId itemId = '218612'; if (curExt() != 'VK') { throw error("This script must run in the VK company!"); } ttsbegin; while select forupdate inventTransOrigin where inventTransOrigin.ReferenceId == workId && inventTransOrigin.ReferenceCategory == InventTransType::WHSWork && inventTransOrigin.ItemId == itemId { inventTransOrigin.delete(); info(strFmt('inventTransOrigin %1 deleted', inventTransOrigin.RecId)); } ttscommit; select firstonly inventTransOrigin where inventTransOrigin.ReferenceId == workId && inventTransOrigin.ReferenceCategory == InventTransType::WHSWork && inventTransOrigin.ItemId == itemId; if (!inventTransOrigin) { info("Success"); } else { warning("Failed"); } } }Please be aware that this framework is designed to handle really small amount of data. The problem is that it start SQL trace - which logs every data update. So for thousands of records it will try to write thousands of entries to log - and this times out in UI. Obviously it will work correctly in DEV environment as it executes as a usual job, however it might fail in Tier-2 environments.
DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics AX.
Authors are allowed to set their own AdSense units.
Join us.