Rename primary key by code
Way 1:
static void CustAccountRename(Args _args) { CustTable custTable; ; select firstOnly custTable where custTable.AccountNum == '1103'; if (custTable.RecId) { custTable.AccountNum = '1103_'; custTable.renamePrimaryKey(); } }
Way 2:
1 void renamePrimaryKey(Common _common) 2 { 3 Common common; 4 FieldId fieldId; 5 DictTable dictTable; 6 DictField dictField; 7 ; 8 common = _common; 9 dictTable = new SysDictTable(common.TableId); 10 dictField = new SysDictField(dictTable.id(), dictTable.primaryKeyField()); 11 12 if (isConfigurationkeyEnabled(configurationkeynum(SIG))) 13 { 14 SIGBaseDocument::checkAndCacheRename(common,dictField.id(),newValue); 15 } 16 17 startLengthyOperation(); 18 fieldId = dictField.id(); 19 try 20 { 21 ttsbegin; 22 // CC Start 23 CCPrimaryKey::renamePrimaryKey(common, dialogField.value(), fieldId); 24 // CC End 25 26 common.(fieldId) = dialogField.value(); 27 28 common.renamePrimaryKey(); 29 if (common.TableId == tablenum(UserInfo)) 30 { 31 common.update(); 32 } 33 ttscommit; 34 } 35 catch (Exception::Error) 36 { 37 ttsabort; 38 } 39 }