Tech Tip: Duplicating a Record with ORDA
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac & Win
Published On: March 7, 2022
With ORDA there is not an equivalent function to the classic style of using the DUPLICATE RECORD command. However, the same behavior can be achieved using the entity functions .toObject() and .fromObject:
var $temp_ob : Object var $firstEnt; $newEnt : cs.Table_1Entity $firstEnt=ds.Table_1.all().first() $temp_ob:=$firstEnt.toObject() $newEnt:=ds.Table_1.new() $newEnt.fromObject($temp_ob) $newEnt.save() |
The following code above acheives the same behavior as the following code:
ALL RECORDS([Table_1]) DUPLICATE RECORD([Table_1]) SAVE RECORD([Table_1]) |
Commented by on August 14, 2023 at 7:35 AM
When I try to do this I get an error at $newEnt.save() indicating a duplicated Key. Do I need to remove the primary key property from the object before executing $newEnt.fromObject($temp_ob)?