{"title":"RecordRef.Rename(Any [, Any,...]) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/recordref/recordref-rename-method/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/recordref/recordref-rename-method, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/recordref/recordref-rename-method","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Changes the value of a primary key in a table.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"RecordRef.Rename(Any [, Any,...]) Method","slug":"recordrefrenameany-any-method","at":0,"chars":3937},{"level":2,"title":"Syntax","slug":"syntax","at":150,"chars":80},{"level":2,"title":"Parameters","slug":"parameters","at":230,"chars":253},{"level":2,"title":"Return Value","slug":"return-value","at":483,"chars":238},{"level":2,"title":"Remarks","slug":"remarks","at":721,"chars":1757},{"level":2,"title":"Example","slug":"example","at":2478,"chars":1322},{"level":2,"title":"Related information","slug":"related-information","at":3800,"chars":137}],"text":"# RecordRef.Rename(Any [, Any,...]) Method\n> Version: _Available or changed with runtime version 1.0._\nChanges the value of a primary key in a table.\n## Syntax\n```al\n[Ok := ]  RecordRef.Rename(Value1: Any [, Value2: Any,...])\n```\n## Parameters\nRecordRef\nType: recordref-data-type\nAn instance of the recordref-data-type data type.\nValue1\nType: ../any/any-data-type\nThe new values for the primary key.\n*[Optional] Value2*\nType: ../any/any-data-type\nThe new values for the primary key.\n## Return Value\n*[Optional] Ok*\nType: ../boolean/boolean-data-type\ntrue if the operation was successful; otherwise false. If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.\n## Remarks\nYou cannot rename some tables. Examples of the types of tables that you cannot rename are:\n Tables in which the user is not allowed to rename the Document No. for legal or business reasons.\n Tables in which an Option data type field, such as Document Type, is part of the primary key.\nSome examples of tables that you cannot rename are:\n Table 36, Sales Header\n Table 38, Purchase Header\n Table 5405, Production Order\n Table 5766, Warehouse Activity Header\nIf an end-user modifies a record between the time that another end-user or another process reads the record and modifies it, then the second user must refresh the value of the record variable before editing the record. Otherwise, the end-user receives the following run-time error:\nAnother user has modified the record for this \\<Table Name> after you retrieved it from the database.\nEnter your changes again in the updated window, or start the interrupted activity again.\nIn earlier versions of Dynamics 365, certain situations allowed code that an end-user runs to modify a record after a newer version of the record was written and committed to the database. This would overwrite the newer changes. However, in Dynamics 365 Business Central, we have restricted the recordref-modify-method, Rename Method \\(RecordRef\\), and recordref-delete-method so that the end-user receives the following run-time error in these certain situations:\nUnable to change an earlier version of the \\<Table Name> record. The record should be read from the database again. This is a programming error.\nYou must design your application so that you use the most up-to-date version of the record for modifications to the database. You use the recordref-get-method to refresh the record with the latest version.\n## Example\nThis example shows how to change the value of the primary key of a Record variable, and how to change the value of the primary key of a RecordRef variable.\n```al\nvar\n    CustRecRef: RecordRef;\n    NewNo1: Code;\n    NewNo2: Code;\n    result: Boolean;\n    CustomerRec: Record Customer;\nbegin\n    CustomerRec.Get('0112121');\n    NewNo1 := ‘9999999’;\n    NewNo2 := ‘8888888’;\n    Message('Customer name: %1; Customer number: %2',CustomerRec.Name, CustomerRec.\"No.\");\n    result := CustomerRec.Rename(NewNo1);\n    if result then\n      Message('After rename - Customer name: %1; Customer number: %2',CustomerRec.Name, CustomerRec.\"No.\")\n    else\n      Message('No rename.');\n    CustRecRef.GetTable(CustomerRec);\n    result := CustRecRef.Rename(NewNo2);\n    if result then begin\n      CustomerRec.Get(NewNo2);\n      Message('After rename 2 - Customer name: %1; Customer number: %2',CustomerRec.Name, CustomerRec.\"No.\")\n    end else\n      Message('No rename.');\nend;\n```\nIf a record with No. 0112121 is found, and if the renames are successful, then the following messages are displayed:\nCustomer name: Spotsmeyer's Furnishings; Customer number: 0112121\nAfter rename - Customer name: Spotsmeyer's Furnishings; Customer number: 9999999\nAfter rename 2 - Customer name: Spotsmeyer's Furnishings; Customer number: 8888888\n## Related information\nrecordref-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}