DEV Community

Peter + AI
Peter + AI

Posted on

πŸš€ Understanding Uniface 10.4 Triggers: A Complete Guide

ℹ️ This blog post was created with AI assistance to help developers understand Uniface trigger concepts better.

πŸ“ What Are Triggers in Uniface?

In Uniface 10.4, triggers are special code blocks that respond to specific events in your application. Think of them like event handlers in other programming languages - they "trigger" when something happens. 🎯

There are two main types:

  • System triggers - automatically called by Uniface (like when data is saved)
  • Interactive triggers - called by user actions (like clicking a button)

πŸ—οΈ Basic Trigger Structure

Every trigger follows this pattern:

trigger TriggerName
    ; Your code goes here
    return
end
Enter fullscreen mode Exit fullscreen mode

The trigger name tells Uniface when to run this code. The end statement marks where the trigger stops. πŸ“

🌐 Web-Enabled Triggers

Uniface 10.4 makes it easy to create web applications. You can mark triggers to work with web browsers:

trigger myWebTrigger
    public web
    ; This trigger can be called from a web browser
    return ("Hello from web!")
end
Enter fullscreen mode Exit fullscreen mode

The public web declaration means this trigger can be called from:

  • Web browsers 🌍
  • REST APIs πŸ”—
  • Other web clients πŸ’»

πŸ“¦ SOAP Integration

SOAP (Simple Object Access Protocol) is a way for different programs to talk to each other over the internet. In Uniface, you can create SOAP-compatible triggers:

trigger soapService
    public soap
    ; This can be called by SOAP clients
    return
end
Enter fullscreen mode Exit fullscreen mode

πŸ”§ Advanced Features

Parameters (params)

Triggers can accept input data called parameters:

trigger calculateTotal
    params
        numeric pPrice
        numeric pQuantity
    endparams

    numeric vTotal
    vTotal = pPrice * pQuantity
    return (vTotal)
end
Enter fullscreen mode Exit fullscreen mode

Scope Definitions

For web applications, scope controls what data gets sent between the client and server:

trigger webDataHandler
    public web
    scope
        ; Define which fields to include
    endscope

    ; Process the data
    return
end
Enter fullscreen mode Exit fullscreen mode

⚠️ Important Rules

  • System triggers cannot use public web - they'll cause compilation errors ❌
  • If you create both a trigger and webtrigger with the same name, only the last one works πŸ”„
  • Web triggers run on the server, not in the browser πŸ–₯️

πŸ’‘ Real-World Example

Here's a practical trigger for a web form:

trigger submitOrder
    public web
    params
        string pCustomerName
        numeric pOrderAmount
    endparams

    variables
        string vMessage
    endvariables

    ; Validate the order
    if (pOrderAmount > 0 && pCustomerName != "")
        ; Process the order
        vMessage = "Order processed successfully!"
    else
        vMessage = "Invalid order data"
    endif

    return (vMessage)
end
Enter fullscreen mode Exit fullscreen mode

🎯 Key Takeaways

  • Triggers are Uniface's way of handling events πŸŽͺ
  • Use public web for browser-accessible triggers 🌐
  • Parameters let you pass data into triggers πŸ“₯
  • Always end triggers with the end statement βœ…
  • Test your triggers thoroughly before deployment πŸ§ͺ

Understanding triggers is essential for building robust Uniface applications. They're the bridge between user actions and your application logic! πŸŒ‰


Keywords: uniface, triggers, webdevelopment, programming

Top comments (0)