Changes the value of a primary key in a table.
[Ok := ] RecordRef.Rename(Value1: Any [, Value2: Any,...])
true 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.
You cannot rename some tables. Examples of the types of tables that you cannot rename are:
Tables in which the user is not allowed to rename the Document No. for legal or business reasons.
Tables in which an Option data type field, such as Document Type, is part of the primary key.
Some examples of tables that you cannot rename are:
Table 36, Sales Header
Table 38, Purchase Header
Table 5405, Production Order
Table 5766, Warehouse Activity Header
If 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:
Another user has modified the record for this <Table Name> after you retrieved it from the database.
Enter your changes again in the updated window, or start the interrupted activity again.
In 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 MODIFY Method (RecordRef), RENAME Method (RecordRef), and DELETE Method (RecordRef) so that the end-user receives the following run-time error in these certain situations:
Unable to change an earlier version of the <Table Name> record. The record should be read from the database again. This is a programming error.
You 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 GET Method (RecordRef) to refresh the record with the latest version.
This 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.
var CustomerRecRef: RecordRef; NewNo1: Code; NewNo2: Code; result: Boolean; CustomerRec: Record Cutomer; begin CustomerRec.GET('0112121'); NewNo1 := ‘9999999’; NewNo2 := ‘8888888’; MESSAGE('Customer name: %1; Customer number: %2',CustomerRec.Name, CustomerRec."No."); result := CustomerRec.RENAME(NewNo1); if result then MESSAGE('After rename - Customer name: %1; Customer number: %2',CustomerRec.Name, CustomerRec."No.") else MESSAGE('No rename.'); CustRecRef.GETTABLE(CustomerRec); result := CustRecRef.RENAME(NewNo2); if result then begin CustomerRec.GET(NewNo2); MESSAGE('After rename 2 - Customer name: %1; Customer number: %2',CustomerRec.Name, CustomerRec."No.") end else MESSAGE('No rename.'); end;
If a record with No. 0112121 is found, and if the renames are successful, then the following messages are displayed:
Customer name: Spotsmeyer’s Furnishings; Customer number: 0112121
After rename - Customer name: Spotsmeyer’s Furnishings; Customer number: 9999999
After rename 2 - Customer name: Spotsmeyer’s Furnishings; Customer number: 8888888