This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v19.8
entitySelection.slice( )
|
entitySelection.slice ( startFrom {; end} ) -> Result | ||||||||
Parameter | Type | Description | ||||||
startFrom | Longint |
![]() |
Index to start the operation at (included) | |||||
end | Longint |
![]() |
End index (not included) | |||||
Result | EntitySelection |
![]() |
New entity selection containing sliced entities (shallow copy) | |||||
The entitySelection.slice( ) method returns a portion of an entity selection into a new entity selection, selected from the startFrom index to the end index (end is not included). This method returns a shallow copy of the entity selection (it uses the same entity references).
Note: This method does not modify the original entity selection.
The returned entity selection contains the entities specified by startFrom and all subsequent entities up to, but not including, the entity specified by end. If only the startFrom parameter is specified, the returned entity selection contains all entities from startFrom to the last entity of the original entity selection.
If the entity selection contains entities that were dropped in the meantime, they are also returned.
You want to get a selection of the first 9 entities of the entity selection:
C_OBJECT($sel;$sliced)
$sel:=ds.Employee.query("salary > :1";50000)
$sliced:=$sel.slice(0;9) //
Assuming we have ds.Employee.all().length = 10
C_OBJECT($slice)
$slice:=ds.Employee.all().slice(-1;-2) //tries to return entities from index 9 to 8, but since 9 > 8, returns an empty entity selection
Product: 4D
Theme: ORDA - EntitySelection
Created: 4D v17
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)