4D Blog

Home Product ORDA – Get started with the entity constructor

ORDA – Get started with the entity constructor

July 15, 2025

Product

The 4D language supports the concept of classes and thus, the concept of constructor.

On the another hand, the ORDA abstraction layer, through Data Model Classes, provides a great business benefit. It allows you to write business-oriented code and “publish” it just like an API. Datastore, dataclasses, entity selections, and entities are all available as class objects that can contain functions as well as computed attributes, and aliases.

This leads your apps to follow easily the MVC principles with powerful and optimized code.

To work with a complete object-oriented approach, starting from 4D 20 R10, entity classes can now have a constructor(). Need to set up initial values when a new entity is instantiated? It’s now possible!  Keep reading to learn more …

HDI_ORDA_constructor

 With ORDA data model classes, data is handled through entities which are instances of the Entity classes you have in your Structure.

The 4D 20 R10 brings the possibility for you to implement a constructor() for entities objects.

The entity constructor

To work with a complete object-oriented approach, starting from 4D 20 R10, entity classes can now have a constructor() which is run when they are instantiated

This is the perfect way to initialize some default values such as a stamp or a createdBy attribute for example.

Before, to do this, you probably implemented a createNew() function in the appropriate dataclass. Given a Products dataclass, your developers must be aware there is a createNew() function in this class and that they must use it instead of naturally instantiate a Products entity using ds.Products.new().

To create a new product, they do:

Form.product:=ds.Products.createNew()

how to implement the constructor

Just implement the constructor() in the entity class.

Here is the ProductsEntity class:

Class extends Entity

Class constructor()
	
This.stamp:=Timestamp()
This.createdBy:=Current user()

And the calling code is so logic. For example, when clicking on the Create product button in a form, just do:

Form.product:=ds.Products.new()

and the Form.product entity comes with the stamp and createdBy attributes properly filled!

 

The constructor() is not only triggered by calling the new() function. Whatever the means the entity is instantiated with, the constructor is triggered.

It can also be:

– the Data explorer (when creating a new entity)

– the fromCollection() function 

– a REST API call creating a new entity on the server (e.g. $method=update)

– code running on the REST server and processing an entity instanciated on a client such as a Qodly app front end or a 4D client using a remote datastore. 

other examples

Given this REST request:

127.0.0.1/rest/Products?method=update

run using a POST with the body:

[
    {"name": "Red pack", "price": 50}
]

Here is the result in the Data explorer. Note the values for the stamp and createdBy attributes.

blank

 

When importing producs with the fromCollection() function:

var $products : cs.ProductsSelection

var $data:=New collection({name: "Red pack"; price: 50}; {name: "Green pack"; price: 10})

$products:=ds.Products.fromCollection($data)

Here is the result. Note the values for the stamp and createdBy attributes.

blank

This blogpost explains how to implement the constructor().

After the reading, if you need to learn more about how the constructor() behaves in C/S or using 4D Qodly pro or when working with a remote datastore, read this blogpost (coming soon).

Check the documentation to learn more and play with the HDI!

Discuss

Tags 20 R10, 21, Class, constructor, data, ORDA, ORDA Data model classes

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

  • AI
  • 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 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 CI/CD 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 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 CI/CD 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