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

Home

 
4D v19.8
entitySelection.slice( )

entitySelection.slice( ) 


 

entitySelection.slice ( startFrom {; end} ) -> Result 
Parameter Type   Description
startFrom  Longint in Index to start the operation at (included)
end  Longint in End index (not included)
Result  EntitySelection in 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 startFrom < 0, it is recalculated as startFrom:=startFrom+length (it is considered as the offset from the end of the entity selection). If the calculated value < 0, startFrom is set to 0.
  • If startFrom >= length, the method returns an empty entity selection.
  • If end < 0, it is recalculated as end:=end+length.
  • If end < startFrom (passed or calculated values), the method does nothing. 

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



See also 

Get query limit
SET QUERY LIMIT

 
PROPERTIES 

Product: 4D
Theme: ORDA - EntitySelection

 
PAGE CONTENTS 
 
HISTORY 

Created: 4D v17

 
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)