update / rename in batch (AX 2.5 )

Hi, can anyone give em a hint, how to use the “right click-rename” function by “code” i have to update a couple of accountnum in the ledgertable and each rename takes minutes to wait. If i could call it frm code “rename accountnum 1234 to 4321” (with all the updates of all the other tables that have reference on this num) would be cool… Thx Pirmin

Hi Pirmin, This is easy to do: see the code behind the Rename button on SysRecordInfo form and adapt it to work from a job/class method rather that from this form. Then use it in a loop for the your accounts. Let me know if you need help to do that.

Hi Pirmin, to rename primary key, just use this: tablename.primarykey = newValue; tablename.renamePrimaryKey(); Hope this help. regards, Khue Trinh

Hi, thx for you responses… do you have a litl more details … as i’m not a “hardcore” developer? Thx Pirmin

Hi… found it… cool saves me lots of “clicks” and a nightshift Pirmin

Hi Pirmin, Below is an example of job that may help you: static void renamePrimaryKey(Args _args) { LedgerTable ledgerTable; str range2rename = '00005,00006,00007'; Query q; QueryBuildDataSource ds; QueryBuildRange r; QueryRun qr; SysOperationProgress simpleProgress; int i; #AviFiles ; q = new Query(); ds = q.addDataSource(tablenum(ledgerTable)); r = ds.addRange(fieldnum(ledgerTable,accountNum)); r.value(range2rename); qr = new QueryRun(q); simpleProgress = SysOperationProgress::newGeneral(#aviUpdate, 'Simple', SysQuery::countTotal(qr)); startLengthyOperation(); while (qr.next()) { ledgerTable = qr.getNo(1); simpleProgress.incCount(); simpleprogress.setText(strfmt("Account: %1", ledgerTable.AccountNum)); ttsBegin; ledgerTable.AccountNum = ledgerTable.AccountNum + '-upd'; ledgerTable.renamePrimaryKey(); i++; ttsCommit; sleep(200); } endLengthyOperation(); info(strfmt("%1 ledger accounts were renamed successfully.",i)); } Thanks, Ciprian