βΉοΈ 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
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
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
π§ 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
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
β οΈ Important Rules
- System triggers cannot use
public web
- they'll cause compilation errors β - If you create both a
trigger
andwebtrigger
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
π― 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)