Skip to content

4d-depot/TechNote_26-03_ORDAEvents

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Technical Note 26-03

ORDA Events in 4D: Controlling Data Operations with Event-Driven Logic

By Abir HSAINI, Technical Services Engineer, 4D Inc.

Abstract

4D 21 introduces a new way to handle database operations using ORDA events. This approach replaces traditional triggers and offers better control over data operations. ORDA events run automatically when data is created, modified, saved, or deleted, allowing developers to add validation, error handling, and business logic directly in their code.

Unlike old triggers that lock entire tables, ORDA events work on individual records and can run in parallel, improving performance in multi-user environments. This document explains how to use ORDA events effectively and provides guidance for migrating from classic 4D triggers to this modern approach.

Introduction

With 4D 21, ORDA events provide a modern event-driven solution for handling database operations in an object-oriented manner, serving as a replacement for classic triggers. These events are implemented as data class functions and are automatically executed when records are created, updated, saved, or deleted, enabling precise control over data lifecycle actions.

Unlike classic triggers, which operate at the table level and can lock entire tables during execution, ORDA events work at the record level. This design enables multiple events to run in parallel on different records, improving multi-user performance. In addition, ORDA events centralize business logic within data classes, making validation rules and processing easier to maintain and more consistent.

ORDA automatically invokes these event functions in response to user actions or code operations, and they cannot be triggered manually. This guarantees consistent business logic across all access channels, including the user interface, REST APIs, and application code. With seven event types covering the full data lifecycle, ORDA events provide fine-grained control over save and drop operations and offer a robust, modern alternative to classic triggers.

Please read the full Tech Note as PDF


🚀 Quick Start

Prerequisites

  • 4D v21 or higher (ORDA events require v21+)
  • Operating System: Windows, macOS, or Linux
  • Minimum RAM: 4GB recommended

Installation Steps

  1. Open with 4D

    • Launch 4D application
    • File → Open → Select the project folder
    • Or double-click the .4DProject file
  2. First Launch

    • The database will open automatically

📊 Database Structure

Tables

┌─────────────┐
│   Client    │
├─────────────┤
│ ID          │
│ Name        │
│ Email       │
│ Phone       │
└─────────────┘

┌─────────────┐
│   Product   │
├─────────────┤
│ ID          │
│ Name        │
│ Description │
│ Price       │
│ Stock       │
│ minimumStock│
└─────────────┘

┌─────────────┐
│    Order    │
├─────────────┤
│ ID          │
│ order_number│
│ Date_Order  │
│ Date_Livr   │
│ ID_Client   │
│ Mode_Pmt    │
│ Price       │
│ Statut      │
│ Description │
└─────────────┘

┌─────────────┐
│ OrderLine   │
├─────────────┤
│ ID          │
│ ID_Order    │
│ ID_Product  │
│ Quantity    │
└─────────────┘

🎯 How to Use

1. Creating a New Order

  1. Open the Orders Form

    • Click "New Order" button in the main window
  2. Fill Order Details

    • Order number: Auto-generated (CMD-YYYY-NNNN)
    • Client: Select from dropdown
    • Date Order: Auto-filled with today's date
    • Delivery date: Optional
    • Payment method: Select (Bank Transfer, Credit Card, etc.)
    • Status: Auto-set to "In progress"
    • Description: Optional comment
  3. Add Products

    • Click "Add new product" button
    • A Form containig products is opened
    • Select products
    • Enter quantity
    • Unit Price and Total calculate automatically
  4. Save the Order

    • Click the "Save" button
    • System automatically:
      • ✅ Validates stock availability
      • ✅ Calculates total order price
      • ✅ Decreases product stock
      • ✅ Saves all changes

About

4D 21 introduces a new way to handle database operations using ORDA events. This approach replaces traditional triggers and offers better control over data operations. ORDA events run automatically when data is created, modified, saved, or deleted, allowing developers to add validation, error handling, and business logic directly in their code.

Topics

Resources

License

Stars

Watchers

Forks

Contributors