4D v17.4

entitySelection.slice( )

Home

 
4D v17.4
entitySelection.slice( )

entitySelection.slice( )  


 

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

 
PROPERTIES 

Product: 4D
Theme: ORDA - EntitySelection

 
PAGE CONTENTS 
 
HISTORY 

 
ARTICLE USAGE

4D Language Reference ( 4D v17)
4D Language Reference ( 4D v17.1)
4D Language Reference ( 4D v17.2)
4D Language Reference ( 4D v17.3)
4D Language Reference ( 4D v17.4)