This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com

Home

 
4D v19.8
entitySelection.add( )

entitySelection.add( ) 


 

entitySelection.add ( entity ) -> Result 
Parameter Type   Description
entity  Entity in Entity to be added to the entity selection
Result  EntitySelection in Entity selection including the added entity

The entitySelection.add( ) function adds the specified entity to the entity selection and returns the modified entity selection.

Note: This method modifies the original entity selection.

Warning: The entity selection must be non-shareable, i.e. it has been created for example by dataClass.newSelection( ) or Create entity selection, otherwise entitySelection.add( ) will return an error. Shareable entity selections do not accept the addition of entities. For more information, please refer to the Shareable vs Alterable entity selections paragraph. 

The entity is added depending on the entity selection is ordered or not (see Ordered vs Unordered entity selections):

  • If the entity selection is ordered, entity is added at the end of the selection. If a reference to the same entity already belongs to the entity selection, it is duplicated and a new reference is added.
  • If the entity selection is unordered, entity is added anywhere in the selection, with no specific order.

The modified entity selection is returned by the function, so that function calls can be chained. 

An error occurs if entity and the entity selection are not related to the same dataClass. If the entity to be added is Null, no error is raised.

 var $employee : cs.EmployeeEntity
 var $employees : cs.EmployeeSelection
 
 $employees:=ds.Employee.query("lastName = :1";"S@") //shareable entity selection
 
 $employee:=ds.Employee.new()
 $employee.lastName:="Smith"
 $employee.save()
 
 $employees:=$employees.copy() //Get a non-shared version of the entity selection
 $employees.add($employee//The $employee entity is added to the $employees entity selection

Calls to the function can be chained:

 var $sel : cs.ProductSelection
 var $p1;$p2;$p3 : cs.ProductEntity
 $p1:=ds.Product.get(10)
 $p2:=ds.Product.get(11)
 $p3:=ds.Product.get(12)
 $sel:=ds.Product.query("ID > 50")
 $sel:=$sel.add($p1).add($p2).add($p3)



See also 

entitySelection.and( )
entitySelection.drop( )
entitySelection.minus( )

 
PROPERTIES 

Product: 4D
Theme: ORDA - EntitySelection

 
PAGE CONTENTS 
 
HISTORY 

Created: 4D v17
Modified: 4D v18 R5

 
ARTICLE USAGE

4D Language Reference ( 4D v19)
4D Language Reference ( 4D v19.1)
4D Language Reference ( 4D v19.4)
4D Language Reference ( 4D v19.5)
4D Language Reference ( 4D v19.6)
4D Language Reference ( 4D v19.7)
4D Language Reference ( 4D v19.8)