KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Entity Selection class .add () function now supports an entitySelection parameter
PRODUCT: 4D | VERSION: 19 R 7 | PLATFORM: Mac & Win
Published On: June 12, 2023

As of 4D v19 R7, the Entity Selection class .add() now supports an entity selection as a parameter. The .add() function adds the specified entity or entity Selection to the original entity selection and returns the modified entity selection.


Example:

var $employees ; $employees2 : cs.EmployeeSelection
var $employee : cs.EmployeeEntity

$employees:=ds.Employee.newSelection()
$employees2:=ds.Employee.query(“lastName = :1”;”H@“)

$employee:=ds.Employee.new()
$employee.lastName:="Smith"
$employee.save()

$employees.add($employee) // $employee entity added
$employees.add($employees2) // $employee2 entitySelection added


Notes:

The entity selection must be alterable, for example needs to be created by .newSelection() or
Create entity selection, otherwise .add() will return an error.

Shareable entity selections do not accept the addition of entities.

If the entity selection is ordered, its order is kept and entitySelection is added at the end of the selection. If references to the same entities of entitySelection already belong to the entity selection, they are duplicated and new references are added.

The modified entity selection is returned by the function, so the function calls can be chained.
An error occurs if entity and the entity selection are not related to the same Dataclass.