When it comes to ORDA, 4D v18 R3 is full of good news! New member methods are at your disposal to further enhance your coding experience.
For starters, extracting data from an entity selection has been greatly enriched allowing you to build a fully customized collection with your entity selection data.
In addition, we’re providing you a way to indicate to an entity selection that its data needs to be refreshed from the server immediately, invalidating cached data.
Interested in some details? Keep reading, everything you need to know is below.
extract data from an entity selection
The new extract() member method is available on an entity selection.
You can now build a customized collection from an entity selection!
Example 1
In the extract() member method, you can specify the dataclass attributes you want to extract and their names in the resulting collection.
Given this simple database:
We build a $mailing collection of objects with specific property names: “recipient, “city”, “zipCode”.
C_COLLECTION($mailing)
$mailing:=ds.Interns.all().extract("lastname";"recipient";\
"employer.city";"city";\
"employer.zipCode";"zipCode")
and here is the resulting
$mailing collection:
[ {recipient:Hodge,city:Blakeslee,zipCode:18610}, {recipient:Metzler,city:Medfield,zipCode:02052}, {recipient:Broyles,city:Madison,zipCode:13402} ]
Example 2
Note that dataclass attributes which are a related entity can be extracted as a collection of entities.
A possible use case is to handle a collection of entities from different dataclasses.
In the example below, we build the Form.partners collection which contains entities from the Company and School dataclasses.
C_COLLECTION($companies;$schools)
// $companies is a collection of entities of Company dataclass
$companies:=ds.Interns.all().extract("employer")
// $schools is a collection of entities of School dataclass
$schools:=ds.Interns.all().extract("school")
Form.partners:=$companies.concat($schools) // Form.partners is a collection
Then, the Form.partners collection is ready to be displayed in a list box!
Check the documentation for the refresh() and extract() member methods to learn more!
Refresh an entity selection
The new refresh() member method is available on an entity selection. It invalidates the entity selection data in the ORDA cache so that the next time you use the data, it triggers an update from the server.
By default, the ORDA cache expires after 30 seconds, so use the refresh() member method just in case you need up to date data immediately.
Example
You have some attributes of the Form.invoices entity selection displayed in a list box and at a given time, you want to display updates done by other clients on those entity selection attributes. Easy! Just use the refresh() member method.
Form.invoices.refresh() // The Form.invoices entity selection displayed data will be refreshed from the server