Tech Tip: Limiting the Number of Entities in an Entity Selection
PRODUCT: 4D | VERSION: 20 | PLATFORM: Mac & Win
Published On: November 19, 2025
When working with entity selections, it can be useful to only return a small subset of entities like the SQL SELECT TOP clause. This can be performed on an entity selection by applying the .slice() function.
The .slice() function takes in two parameters:
- The first parameter is the inclusive index of the first entity.
- The second parameter is the optional excluded index of the entity to stop at. If omitted, all entities from the first parameter are returned.
To get the first 20 entities of an entity selection something like the following can be performed:
The above will return the first 20 entities from index 0 to index 19.
This can be useful to test some looping code without needing to run through a larger dataset.
The function can also be applied to grab any subset within the entity selection and can also be used to parse entities in chunks by incrementing the two parameters by the chunk amount.
The .slice() function takes in two parameters:
- The first parameter is the inclusive index of the first entity.
- The second parameter is the optional excluded index of the entity to stop at. If omitted, all entities from the first parameter are returned.
To get the first 20 entities of an entity selection something like the following can be performed:
| $myEntSel:=ds.Table_1.all().slice(0;20) |
This can be useful to test some looping code without needing to run through a larger dataset.
The function can also be applied to grab any subset within the entity selection and can also be used to parse entities in chunks by incrementing the two parameters by the chunk amount.