Tech Tip: How to copy a collection of entities
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac & Win
Published On: January 30, 2023
Suppose a collection of entities needs to be copied to another collection. Since entity objects are not copiable, using collection.copy() will return a collection of null values. Instead, use collection.combine() or collection.query(). For example:
$coll:=New collection $ent_sel:=ds.Table_1.all() For each ($ent; $ent_sel) $coll.push($ent) End for each $coll_copy:=New collection.combine($coll) |
In the above code, $coll_copy will return the same collection of entities as $coll. Using collection.query(), the last line can be replace with the line below:
$coll_copy:=$coll.query() |
In the line above, all entity elements from the original collection are essentially put into the copy when no query parameter is passed.