4D Blog

Home Product More sophisticated ORDA queries with formulas

More sophisticated ORDA queries with formulas

August 6, 2019

Product

In 4D v17 R6, ORDA queries are becoming increasingly more powerful and concise. This blog post is for those of you who need more sophisticated search criteria than just a simple syntax like “name = Smith‘”. With this R-release, you can use any project method or 4D expression in the query() member method by using formulas.

What better way to explain this feature than with an example? Let’s dig into the details.

HDI: Example of ORDA queries using formulas

WRITE A QUERY USING a FORMULA

The query() member method has been updated to support a single Formula object as a parameter.

Example

In the Students dataClass, we search for students with a score in English higher than their overall average score.

Note that each entity is accessed by the formula with the This command.

C_OBJECT($formula;$students)
// In the Students dataClass, grades is an object field containing students' grades for each subject
// Example of JSON representation of the grades object field:
// {math:50,english:90,history:85}
// The studentAverage project method computes the student's overall average in all subjects
$formula:=Formula(This.grades.english>studentAverage (This))
$students:=ds.Students.query($formula)

use a Formula with other search criteria

Formulas can easily be combined with other search criteria. Below is an example to show you how.

Example

In the Students dataClass, we continue to search for students with a score in English higher than their overall average AND whose country is England.

The $formula object is used as a placeholder value, like any other one.

C_OBJECT($formula;$students)
C_TEXT($country) // $country = "France"

$formula:=Formula(This.grades.english>studentAverage (This))
$students:=ds.Students.query(":1 and country=:2";$formula;$country)

use a formula in the query string

A formula can also be inserted in the query string with an eval() statement.

While this can be convenient for quickly coding a query, you’ll miss the advantages from using a formula object (such as autocompletion, colors in the code editor, and search callers).

C_OBJECT($students)
C_TEXT($country) // $country = "France"

$students:=ds.Students.query("eval(This.grades.english > studentAverage (This)) and country=:1";$country)

NOTE: The query() member method on the entity selection object has also been updated to support formulas. Check the documentation to learn more.

Discuss

Tags Formula, ORDA, v17 R6, v18

Latest related posts

  • December 3, 2025

    Give AI to a 30 years old 4D application

  • November 28, 2025

    ORDA – Handle an event-driven logic during database operations

  • November 27, 2025

    ORDA – Permissions – Restrict / allow web access to the resources in one click

Avatar
Marie-Sophie Landrieu-Yvert
- Product Owner - Marie-Sophie Landrieu-Yvert joined the 4D Product team as a Product Owner in 2017. In this role, she is responsible for writing user stories and translating them into functional specifications. She also ensures that the delivered feature implementation meets the customer's needs. Marie-Sophie graduated from the engineering school ESIGELEC and began her career as an engineer at IBM in 1995. She took part in various projects (maintenance and development projects) and worked as a COBOL developer. She then moved on to work as a UML designer and Java developer. More recently, her main responsibilities included analyzing and writing functional requirements, and coordinating business and development teams.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • 4D View Pro
  • AI
  • 4D Write Pro
  • 4D for Mobile
  • Email
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • Qodly Studio
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D-Analyzer 4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R10 21 Administration AI Artificial Intelligence Build application Class Client/Server Code editor Collections Formula Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor

Tags

4D-Analyzer 4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R10 21 Administration AI Artificial Intelligence Build application Class Client/Server Code editor Collections Formula Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor
Subscribe to 4D Newsletter

© 2025 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy