Skip to main content

Posts

Showing posts with the label Primary Key

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(); ...