KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to Display Entity Selection in List Boxes Efficiently
PRODUCT: 4D | VERSION: 20 | PLATFORM: Mac & Win
Published On: July 22, 2024

There are three options to consider when displaying an entity selection:
1. Directly displaying the entity selection
   - Optimized and fast, but the columns displayed can only be attributes of the entity
2. Collection of Entity Values
   - Allows for columns other than entity attributes, but loses references to the entities
   - If you want to update values you need to send another query
3. Collection of Entity References
   - Allows for columns to be outside of the entity attributes and keeps the references to the entities,
      but is slower and more computationally expensive
   - These entities will stay in memory until all references are gone
    - Not reccomended for large selections

Option 1 Code:

Form.currentSelection:=ds.Contact.all()


Option 2 Code:
$col:=New collection
$sel:=ds.Contact.all()
$col:=$sel.toCollection()
For each ($element; $col)
   $element.new_property:="text"
End for each
Form.currentSelection:=$col


Option 3 Code:
C_OBJECT($sel; $entity; $obj)
C_COLLECTION($col)
$col:=New collection
$sel:=ds.Contact.all()
For each ($entity; $sel)
   $obj:=New object
   $obj.new_property:="text"
   $obj.entity:=$entity
   $col.push($obj)
End for each
Form.currentSelection:=$col

* For Option 3, the list box references the entity attributes through This.entity.attribute