Triggers are handlers that run at defined points. TriggerType lists the points. A TriggerDefinition binds a handler to one of them.

Trigger types

The TriggerType enum is grouped by numeric range.

GroupValues
Form0 to 14
Block20 to 44
Record50 to 55
Item70 to 81
Navigation100 to 119
Action120 to 138
Function keys and other150 to 168
Mouse170 to 178
TimerWhenTimerExpired (190)
CustomCustom1 to Custom5 (200 to 204), WhenMenuItem (205), UserNamed (250)

Each enum member carries a comment saying when it is meant to fire. Read the enum in the source for the full list of names.

Defining a trigger

manager.Triggers.RegisterTrigger(new TriggerDefinition(
    TriggerType.WhenValidateItem, TriggerScope.Item)
{
    TriggerId = "ord.qty.WhenValidateItem",
    BlockName = "Ord", ItemName = "Qty", Handler = OnValidateQty,
});

TriggerScope is one of Form, Block, Record, Item, Global. The constructor fills TriggerName, Category and Timing. Other members include AsyncHandler, TimeoutMs, ContinueOnFailure, DependsOn, ChainMode, IsEnabled and Priority. Static helpers are CreateFormTrigger, CreateBlockTrigger, CreateItemTrigger and CreateAsyncBlockTrigger.

Manager methods

RegisterTrigger, RegisterFormTrigger, RegisterBlockTrigger, RegisterItemTrigger, RegisterGlobalTrigger and their async variants register handlers. UnregisterTrigger and ClearBlockTriggers remove them. FireFormTrigger, FireBlockTrigger and FireItemTrigger run them. SuspendTriggers and ResumeTriggers pause and resume firing. EnableTrigger and DisableTrigger switch one trigger.

Execution order

  • Triggers run in descending Priority. TriggerPriority values are Lowest 0, Low 25, Normal 50, High 75, Highest 100 and System 255.
  • A form fire runs global and form triggers. A block fire runs global and block triggers. An item fire runs global, block and item triggers.
  • The chain stops when Cancel or SkipRemainingTriggers is set on the context. A failing trigger without ContinueOnFailure sets SkipRemainingTriggers.
  • A result of FormTriggerFailure or a cancel makes the overall result FormTriggerFailure. A result of Cancelled makes the overall result Cancelled.

TriggerResult members are Success, Failure, Exception, Cancelled, Skipped, Timeout and FormTriggerFailure. TriggerChainMode members are StopOnFailure, Continue and Rollback.

The context

A handler receives a TriggerContext. Useful members: Cancel, CancelMessage, Message, SkipRemainingTriggers, RaiseFormTriggerFailure(message), Parameters, GetParameter<T>, SetParameter, OldValue, NewValue, CurrentRecord, KeyCode, TimerName and FormsManager.

Triggers with known parameters

  • WhenTimerExpired fires at form scope with Parameters["TimerName"] and Parameters["FireCount"].
  • WhenMenuItem fires with Parameters["MenuItemId"] and Parameters["MenuItemCommand"].
  • When an item value changes on the current record and the item has a list of values, WhenLOVValidation fires first, then the list membership check runs.

Key triggers

manager.RegisterKeyTrigger(KeyTriggerType, blockName, handler) registers a handler for a key. An empty or null block name means form scope. FireKeyTriggerAsync(KeyTriggerType, blockName) runs it. When the result is not Cancelled, the default action runs.

Key triggerDefault action
Enter, CommitCommitFormAsync
ExitCloseFormAsync
ExecuteQueryExecuteQueryAsync
NextRecord, PreviousRecordRecord navigation
NextBlock, PreviousBlockBlock switch
OthersNone

Which engine operations raise which trigger

This page documents the firing points that were checked in the engine: the item, block and form chains above, key triggers, timers, menu items and list of value validation. Do not assume every member of TriggerType is raised by the built in operations. A trigger you register yourself can always be run with the Fire methods.