KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Querying Entity Selections
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac & Win
Published On: April 4, 2022

An efficient use of the ORDA mechinism is performing queries on entity selections. For example, a query of records with a date field value for a specific year was performed and a selection of records were returned, a query can be performed on the selection to get the records for a specific month of the year.

Using the classic method, first a QUERY would be performed and then a QUERY SELECTION.
With ORDA a second query can be performed on the entity selection.

With ORDA it can be easier when multiple sub sets of the selection are needed, such as a sub set for each month.

With the classic method, the original selection would need to be saved into a Set or Named selection. After the QUERY SELECTION is performed, the original selection would need to be reloaded.

With ORDA, the original selection can be stored on a variable and easily used as needed.

For example, the following code will generate a subselection of the entity selections with the dateField value within each month in the for loop :

$dateStart:=!2020-01-01!
$dateEnd:=!2021-01-01!

$entitySelection:=ds.Table_1.query("dateField >= :1 AND dateField < :2"; $dateStart;$dateEnd)

For($i;1;12)
  $dateStart:=Date(String($i)+"/01/2021")
  $dateEnd:=Date(String($i+1)+"/01/2021")

  $subSel:=$entitySelection.query("dateField >= :1 AND dateField < :2"; $dateStart;$dateEnd)

//... some code

End for

As shown, the original entity selection in the $entitySelection variable is maintained and can continue to be easily used in other places of the method after the for loop.