Skip to main content

Posts

Showing posts with the label rename

Batch-renaming a primary key.

For a programmer who has experienced the "terror" of having to batch-rename primary keys in Dynamics AX's predecessor XAL/C5, I was pleasantly surprised to find how easy it is in Dynamics AX 2009. Though not documented a method called renamePrimayKey exists on the kernel class xRecord which each table apparently inherits from. If you call this method after changing the primarykey field on a tablebuffer, this change will be cascaded to related tables. :0) I was given a task to perform renaming of Items in the InventTable. In an environment that is to go live - so THERE WERE NO TRANSACTIONS OG STOCK LEVELS . If this has been the case we would have adviced the customer to live with it, as the renaming process potentially would have taken a very long time Nearly 75% of the item numbers were named with 4 digits, the rest with 5. The customer wanted only 5-digit item numbers. How to do this in one go ? A simple job is enough: static void Job7(Args _args) { In...

Rename a Primary Key in AX through code

In this post, I am going to discuss about how to rename a primary key in AX. The renaming can be done for any record using the CCPrimaryKey Class. Let us suppose, if Customer Id 1000 has to be renamed as Cust_1000 then it will be renamed in all the tables(SalesTable, CustTable, SalesQuotationTable etc.,) wherever this cutomer Id has been used. The generic way to rename a primary key for any table is as follows:   Send a record to this method as a parameter. void renamePrimaryKey(Common _common) { Common   common; FieldId fieldId; DictTable dictTable; DictField   dictField; ; common = _common; dictTable = new SysDictTable(common.TableId); dictField = new SysDictField(dictTable.id(), dictTable.primaryKeyField()); if (isConfigurationkeyEnabled(configurationkeynum(SIG))) {   SIGBaseDocument::checkAndCacheRename(common,dictField.id(),newValue); }   startLengthyOperation(); fieldId = dictField.id(); ...

rename items quickly

Here is a little script to rename items quickly. Just provide a CSV file with old and new item number. I found that making the CSV file was faster than making a job to intelligently rename items because I could use Excel functions and review the new item numbers faster static void renameFromCSV(Args _args) { #File CommaIO file; Container values; Dialog dialog; DialogField dfFileName; LineNum lineNum; ItemID itemIDfrom; ItemID itemIDto; InventTable inventTable; ; setPrefix(funcName()); dialog = new Dialog("Rename items"); dialog.filenameLookupFilter(["@SYS39829", #AllFilesName + #csv]); dfFileName = dialog.addField(typeid(FileNameOpen)); if (!dialog.run() || !dfFileName.value()) return; if (!WinAPI::fileExists(dfFileName.value())) throw error(strfmt("@S...