Modifying primary key

Hi ,

Please i need to modify or change a value to primary key by coding .

How can i do it .

for example table 5722 – code and description

C cake

f finished

i need to change C to CK for example …

IF “Item Category”.Code = ‘C’ THEN BEGIN
“Item Category”.Code := ‘CK’ ;
“Item Category”. MODIFY ;

this of course up will not work … how could i do it ?

thank you for any one could help .

Hi Jouhayna,

You cannot use MODIFY when changing the primary key value use RENAME instead.

1 Like

Hi Jouhayna,

One thing to check prior to use rename that the Rename trigger on table should not have any error statement written or you need to comment it .

You could also use Temporary table (of the same record) to achieve the above.

1.Move the record into temporary table with the changed key.

  1. Delete the original record from the main table.

  2. Copy the record from Temporary table to Main Table.

Hope this help.



No that is definately NOT the right way to go about that, because that will ignore all table relations. Doing a rename will also update tables that have a relation into this table. Deleting it and replacing it with another record will not automtically take care of that. You owuld have to write and run code to update those values.

RENAME is the best way to do it.

Hi experts,

thank you all for your help … really i cannot do rename because of Replication .

I will try to use the temporary table to reach my solution …

thank you again for you all

1 Like

You have to use RENAME instead of MODIFY.

[Ok]:= Record.RENAME(Value1, [Value2],…)


Data type: boolean

This tells you whether the system was able to rename the primary key or not. Typically, the system will return FALSE if the record does not exist or if you do not have permission to write to the table.


Data type: record

The record that contains the primary key that you want to change.

Value1, Value2, …

Data type: text

The new values for the primary key.


you can not Modify a primary key field using MODIFY function instead we need to use RENAME function.

Example: in yours

“Item Category”.Get(‘C’);

“Item Category”.RENAME(‘CK’);