ORDA is a major innovation of 4D v17, this is why we’re dedicating an entire series of blog posts to ORDA. While ORDA has its own concepts that are very different from the classic approach, it’s still possible to mix ORDA with your existing code.
In a nutshell, this blog post will show you how you can update the current selection of a table from an entity selection and get an entity selection from the current selection of a table. It’ll allow you to smoothly integrate ORDA concepts into your existing 4D code, step by step.
With ORDA, data is accessed through an abstraction layer: the datastore. A datastore is an object which provides an interface to the database and its data through objects. And remember, with ORDA each table is mapped with a dataclass.
Once you have an entity selection related to a dataclass, you can update the current selection of the corresponding [Table] with the USE ENTITY SELECTION command. And, once you have a current selection on a [Table], you can get an entity selection related to the corresponding dataclass wtih the Create entity selection command.
Current selection from an entity selection
In the code below, the $entitySelection entity selection is related to the Employee dataclass which actually corresponds to the same-named [Employee] table. The USE ENTITY SELECTION command updates the current selection of the table accordingly.
// The current selection of the [Employee] table is replaced according to the content of $entitySelection
USE ENTITY SELECTION($entitySelection)
//... Go on with your classic 4D code ...
entity selection from Current selection
Here, the current selection has been updated after performing a query on the [Employee] table. The Create entity selection() command creates the $entitySelection entity selection accordingly. The created entity selection is related to the Employee dataclass.
// The current selection of the [Employee] table is updated after the query
// $entitySelection is created from the current selection of the [Employee] table
$entitySelection:=Create entity selection([Employee])