Business Central — How to change primary key of a record

table 55047 "Sample Line Data" 
field(1; "Entry No."; Integer) { Caption = 'Entry No.'; }
field(2; "Line No."; Integer) { Caption = 'Line No.'; }
field(3; "Item Code"; Code[10]) { Caption = 'Item Code'; }
field(4; "Item Description"; Text[50])
{ Caption = 'Item Description'; }
key(PK; "Entry No.", "Line No.") { Clustered = true; }
[Ok := ] Record.Rename(Value1: Any [, Value2: Any,...])
// #1 change part of primary key, line no from 1000 to 2000 
if MyRecord.Get(1,1000) then
MyRecord.Rename(MyRecord."Entry No.", 2000);
// #2 get record again with new key
if MyRecord.Get(1, 2000) then
begin // #3 update item description (non key field)
MyRecord."Item Description" := 'Changed Description';



Appreciating the Journey More Than the Destination

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store