๐Ÿš€ Uniface Trigger Activation: When One Click Creates a Chain Reaction
Peter + AI

Peter + AI @petercode

Joined:
Jul 12, 2025

๐Ÿš€ Uniface Trigger Activation: When One Click Creates a Chain Reaction

Publish Date: Jul 12
0 0

This post is based on Uniface Documentation 10.4 and was created with AI assistance.

Hey developer community! ๐Ÿ‘‹

Today we're diving into the fascinating world of Uniface trigger activation. If you've ever worked with event-driven applications, you know how complex the behind-the-scenes processes can be. Uniface is no exception โ€“ but fortunately, there's a clear logic behind it! ๐Ÿง 

๐ŸŽฏ What Are Triggers in Uniface?

Uniface applications are event-driven. This means that certain events activate corresponding triggers. These triggers can be activated by various sources:

  • ๐Ÿ‘ค User actions (clicks, inputs, etc.)
  • ๐Ÿ“ ProcScript statements
  • ๐Ÿ”” External events (asynchronous interrupts)

When an event occurs, the corresponding trigger is activated, and the script contained within determines what happens next. Pretty straightforward, right? ๐Ÿค”

๐Ÿ”„ Implicit Trigger Activation

Here's where it gets interesting! Some events happen implicitly โ€“ meaning they're automatically triggered without you having to explicitly program them.

A typical example in Form components:
๐Ÿ” loseFocus - Field-level trigger
๐Ÿ”‘ leaveModifiedKey - Occurrence-level trigger
โœ๏ธ leaveModified - Occurrence-level trigger

Imagine this: A user modifies a key field and attempts to store the data without actually leaving the field. What happens behind the scenes? ๐ŸŽญ

๐ŸŒŠ Cascading Processing

This is the exciting part! A single user click can trigger a chain reaction. Let's look at what happens when storing (^STORE) in a Form component:

The Domino Effect ๐Ÿ€„

  1. ๐Ÿ–ฑ๏ธ User clicks a button โ†’ ^STORE function is activated

  2. โœ… Uniface automatically activates the required validation triggers:

    • validate and validateKey (data validation)
    • loseFocus, leaveModifiedKey, leaveModified (event completion)
  3. ๐Ÿ’พ Store trigger of the component is activated

  4. โœ๏ธ Write trigger is activated for every modified entity occurrence

  5. ๐Ÿ” formatToDbms trigger is activated for each field

  6. ๐Ÿ—ƒ๏ธ Data is passed to the database connector and stored in the database

๐Ÿงฉ The Different Trigger Levels

Uniface organizes triggers in different hierarchy levels:

Level Example Triggers Description
๐Ÿ—๏ธ Component store, accept, preActivate, postActivate, receiveMessage, quit Acts on the entire component
๐Ÿ“Š Occurrence write, delete, validate, validateKey, writeUp, deleteUp Acts on record level
๐Ÿท๏ธ Field loseFocus, formatToDbms, formatFromDbms, validate, error Acts on individual fields

โš ๏ธ Important Note for Developers

Here's a critical point: If you omit the store statement in the store trigger, the write trigger won't be activated! This means your data won't be saved to the database. ๐Ÿ˜ฑ

; โœ… Correct - activates write trigger
store

; โŒ Wrong - write trigger won't be activated
; (store statement missing)
Enter fullscreen mode Exit fullscreen mode

๐Ÿ†• Uniface 10 Specific Features

Explicit Trigger Declaration ๐Ÿ“

One of the most important changes in Uniface 10 is that triggers must be explicitly declared using the trigger statement:

trigger triggerName
  ; Your trigger code here
  ; Example: validation logic, data processing, etc.
end
Enter fullscreen mode Exit fullscreen mode

This is a significant departure from earlier versions where triggers could be implicitly defined. Every trigger you want to use must be explicitly declared, even if it only contains comments or whitespace.

Default Behavior Clarification ๐Ÿ”ง

It's important to understand that most triggers have NO default behavior. This means:

  • If you don't define a trigger, nothing happens when the corresponding event occurs
  • Only a few specific triggers have implicit behavior that activates when no explicit trigger is defined
  • This gives developers complete control over application behavior

Inheritance and Override Rules ๐Ÿ—๏ธ

In Uniface 10, trigger inheritance follows strict rules:

  • Local trigger declaration breaks inheritance - even if the trigger is empty
  • When you declare a trigger locally, it completely overrides any inherited behavior
  • This applies even to triggers that contain only comments or whitespace
; This breaks inheritance even though it's "empty"
trigger validate
  ; Even this comment breaks inheritance!
end

; This also breaks inheritance
trigger validate

end
Enter fullscreen mode Exit fullscreen mode

๐ŸŽฏ The Complete Processing Flow

When a user performs a simple "modify and store" action, Uniface actually processes multiple triggers behind the scenes:

  • loseFocus - field-level trigger
  • leaveModifiedKey - occurrence-level trigger
  • leaveModified - occurrence-level trigger
  • store - component-level trigger
  • write (or writeUp) - occurrence-level trigger for every occurrence that needs updating
  • formatToDbms - field-level trigger for every field stored in encrypted format
  • delete (or deleteUp) - occurrence-level trigger for every removed occurrence

Much of this processing can be handled with single ProcScript instructions like store, write, and delete. If all triggers complete successfully, the user's data is correctly stored in the database.

๐ŸŽผ Best Practices for Uniface 10 Developers

1. Always Declare Your Triggers Explicitly โœ…

trigger validate
  ; Always use explicit trigger declaration
  if (fieldvalue < 0)
    error "Value must be positive"
  endif
end
Enter fullscreen mode Exit fullscreen mode

2. Understand Inheritance Impact ๐Ÿ”„

; Be aware that this breaks inheritance
trigger validate
  ; Your custom validation
  ; Parent validation is NO LONGER called
end
Enter fullscreen mode Exit fullscreen mode

3. Handle Cascading Carefully โšก

trigger store
  ; Remember: omitting 'store' prevents write triggers
  store  ; This line is CRITICAL
end
Enter fullscreen mode Exit fullscreen mode
  1. Document Your Trigger Dependencies ๐Ÿ“š
trigger write
  ; This trigger depends on:
  ; - validate trigger completing successfully
  ; - formatToDbms trigger for field formatting
  ; - store trigger activation
end
Enter fullscreen mode Exit fullscreen mode

๐Ÿ” Debugging Trigger Chains

When debugging complex trigger chains, consider:

  • Enable trace logging to see trigger activation sequence
  • Use breakpoints in critical triggers like validate and write
  • Check for missing explicit declarations - a common source of bugs in Uniface 10
  • Verify inheritance behavior - ensure parent triggers are called when expected

๐ŸŽผ Summary

Trigger activation in Uniface is like a perfectly orchestrated symphony:

  • A single event can trigger a complex chain of triggers
  • Uniface automatically handles data validation and integrity
  • The hierarchy (Component โ†’ Occurrence โ†’ Field) ensures structured processing
  • Each trigger has its specific role in the overall process
  • Uniface 10 requires explicit declaration of all triggers
  • Inheritance rules are strict - local declaration always overrides parent behavior

๐Ÿค Conclusion

Uniface's event-driven architecture may seem complex at first glance, but it provides a powerful and flexible foundation for robust applications. The automatic cascading processing ensures that your data remains consistent and validated โ€“ even when much more is happening behind the scenes than the user sees! ๐Ÿ”

Uniface 10 brings additional structure and control through explicit trigger declarations, giving developers complete control over application behavior while maintaining the powerful cascading capabilities that make Uniface unique.

The beauty of this system lies in its implicit intelligence โ€“ developers don't need to manually orchestrate every step of the validation and storage process. Uniface handles the complexity while providing clear extension points through triggers.

Understanding these concepts is crucial for building maintainable, robust Uniface applications. The explicit nature of Uniface 10 triggers might require more initial setup, but it provides better code clarity and prevents many common inheritance-related bugs.

Have you worked with Uniface triggers before? How has your experience been with the transition to Uniface 10's explicit trigger declarations? Share your experiences in the comments! ๐Ÿ’ฌ

Based on Uniface Documentation 10.4 - Trigger Activation (last updated: August 22, 2024)

Comments 0 total

    Add comment