4D Blog

Home Product ORDA member methods to get the structure information

ORDA member methods to get the structure information

May 28, 2019

Product

“How can I know the dataClass of an entity? I need it to write generic methods“. “I need information about a field in a dataClass: what is its type? Is it indexed? Is it unique?“. These are the kinds of questions we’ve heard you asking on the forum. 4D v17 R5 provides the answers: introducing new ORDA member methods to provide useful information about your database. Keep reading, because you’ll appreciate the benefits of reducing the size of your code and making it reusable and easy to maintain!

HDI: Example of getting database structure information with ORDA

Now, you can get structure-related information such as table or field number. This can be helpful when integrating ORDA  step-by-step into your classic 4D code. However, the main purpose of these member methods is to give you a way to write generic code that’s applicable no matter the database’s structure.

Get the dataClass of an entity or an entity selection

entity dataclass

What a joy to have a clever entity that knows its own dataClass!

The getDataClass() member method returns the dataClass object corresponding to the entity. Then, you can call any member method available on the dataClass.

In the example below, we call the new() member method. It creates a new entity from the one provided and copies the address data. An object containing the property name and its value for the newly created entity is also received. 

C_OBJECT($1;$entity;$entityContent;$newEntity;$status)
C_OBJECT($2;$attribute)

$entity:=$1
$attribute:=$2

$newEntity:=$entity.getDataClass().new()

$entityContent:=$entity.toObject("address.*")
//We copy address from the received entity
$newEntity.fromObject($entityContent)

//We fill the created entity with received property name and value
$newEntity[$attribute.name]:=$attribute.value
$status:=$newEntity.save()

entity selection dataclass

The getDataClass() member method returns the dataClass object corresponding to the entity selection. The method below receives an entity selection and creates new entities with the same address data.

C_OBJECT($1;$inputSelection;$newEntitySelection)
C_COLLECTION($esContent)
$inputSelection:=$1
alert(String($inputSelection.length) + " entities are going to be duplicated")
$esContent:=$inputSelection.toCollection("address")
$newEntitySelection:=$inputSelection.getDataClass().fromCollection($esContent)
alert(String($newEntitySelection.length) + " entities have been created")

get information about a dataclass

The getInfo() member method available on the dataClass, also returns useful information. In the example below, we get IDs matching the primary key of the Persons dataClass, then we retrieve the corresponding entities.

C_OBJECT($es;$settings)
$settings:=New object
$settings.parameters:=New object("receivedIds";getIds ())
// The getIds() method returns a collection of IDs
$settings.attributes:=New object("pk";ds.Persons.getInfo().primaryKey)
$es:=ds.Persons.query(":pk in :receivedIds";$settings)

dataclass attribute

With 4D V17.0, you learned that each dataClass attribute is an object. They’ve now been enhanced with conceptual and structural information.

Here’s a quick example.

C_TEXT($text)
$text:=JSON Stringify(ds.Cats.ID)
//$text =
//{"name":"ID","kind":"storage","type":"number","indexed":true,
//"keywordIndexed":false,
"autoFilled":true,"mandatory":true,"unique":true,
//"fieldNumber":1,"fieldType":9}

Download the HDI above to learn more! And be sure to check out the doc center.

Discuss

Tags ORDA, Programming, v17 R5, v18

Latest related posts

  • May 20, 2025

    Automatic Refresh of OEM Build Licenses

  • May 16, 2025

    New class to handle incoming TCP connections

  • April 29, 2025

    Discover your AI-powered writing assistant in 4D Write Pro

Avatar
Marie-Sophie Landrieu-Yvert
• Product Owner • Marie-Sophie Landrieu-Yvert has joined the 4D Product team as a Product Owner in 2017. As a Product Owner, she is in charge of writing the user stories then translating it to functional specifications. Her role is also to make sure that the feature implementation delivered is meeting the customer need.Marie-Sophie graduated from the ESIGELEC Engineering School and began her career as an engineer at IBM in 1995. She participated on various projects (maintenance or build projects) and worked as a Cobol developer. Then she worked as an UML designer and Java developer. Lately her main roles were analyzing and writing functional requirements, coordinate business and development teams.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • 4D View Pro
  • 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 for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R8 20 R9 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Listbox Logs Mail Microsoft 365 Network Objects ORDA PDF Pictures Preemptive Programming Qodly Studio REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor

Tags

4D-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R8 20 R9 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Listbox Logs Mail Microsoft 365 Network Objects ORDA PDF Pictures Preemptive Programming Qodly Studio 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