Creating an Event Binding
This page explains how to bind an action to an event of a function, how to write the action expression and which helper functions can be used in it. For the concept of events and the list of supported functions, see the Events Overview.
Steps to Add an Event Binding
1. Open the Function Designer
Click Function Designs under the Administration menu.
2. Open the Events of the Function
- On the Functions list, find the function (for example Work Order or Material Transaction).
- Click Events in the row actions. The action is shown only for functions that publish events.
3. Add a New Binding
- Click the New button at the top right. The New panel opens from the right over the list.
4. Fill in the Fields and Save
- Select the Event and write the Action expression.
- Click Save. The binding is saved and appears in the list. Clicking outside the panel does not close it; use Cancel to leave without saving.
To change a binding, click Edit in its row (the Edit panel opens); to remove it, click Delete and confirm.
Fields of an Event Binding
Required fields are shown in bold.
| Field Name | Description |
|---|---|
| Event | The event the binding reacts to, selected from the events the function publishes (for example OnTaskStarted, OnTaskCompleted, OnCreated, OnUpdated). It cannot be changed after the binding is created; to react to another event, create a new binding. |
| Action | The expression that runs when the event occurs. It is written as a single expression and can call the helper functions listed below, use the record's fields and combine them with conditions. |
Writing the Action Expression
The action is a single expression in a C#-like syntax:
- Helper functions are called by name with their parameters in parentheses, for example
WorkOrderChangeState("InProgress", "InProgress"). Text values are written in double quotes. - Record fields are available as variables named after the field with a lower-case first letter, for example
id,state,title,transactionNumberorworkOrderId. Only simple fields (text, number, date, identifier, yes/no) are available; linked records and lists are not. - Conditions are written with the conditional operator
condition ? action : falseor with&&, for examplestate == "Approved" ? PushMaterialTransactionToErp("ERP-Main") : false. - Common types such as
DateTime,Math,string,GuidandTimeSpancan be used in conditions.
The record the event was raised for is known to the helper functions, so you never pass its identifier yourself.
Work Order Helper Functions
| Function | What it does |
|---|---|
WorkOrderChangeState("<state>", "<state category>") | Sets the work order's state and state category directly, without going through the state transitions. Nothing is changed if the work order is already in that state category. |
WorkOrderChangeStateIfAllTasksCompleted("<state>", "<state category>") | Does the same, but only when the work order has at least one task and all of its tasks are completed. |
WorkOrderUpdateByAction("<action>", "<states>") | Runs a state transition action of the work order, in the same way as the action buttons of the work order. <states> is a comma-separated list of state values; when it is filled, the action runs only if the work order is currently in one of these states. Leave it empty ("") to run the action in any state. |
The state category must be one of the work order state categories (for example Draft, Request, Approved, InProgress, OnHold, Completed, Closed, Cancelled, Rejected). See Work Order and the State Overview.
Material Transaction Helper Functions
| Function | What it does |
|---|---|
PushMaterialTransactionToErp("<integration name>") | Queues the transaction to be sent to the named push integration in the background and creates an entry in the integration's work history. The integration must exist, be active and be of the push type; otherwise nothing is sent. |
MaterialTransactionHasQuantityAbove(<threshold>) | Returns true when the total quantity of the transaction's materials is greater than the threshold. Useful as a condition, because the material lines themselves are not available as variables. |
Push integrations are described under Integrations.
Examples
| Goal | Event | Action |
|---|---|---|
| Move the work order to In Progress when a task starts (default). | OnTaskStarted | WorkOrderChangeState("InProgress", "InProgress") |
| Complete the work order when all tasks are done (default). | OnTaskCompleted | WorkOrderChangeStateIfAllTasksCompleted("Completed", "Completed") |
| Send every new material transaction to the ERP. | OnCreated | PushMaterialTransactionToErp("ERP-Main") |
| Send only large transactions. | OnCreated | MaterialTransactionHasQuantityAbove(100) ? PushMaterialTransactionToErp("ERP-Main") : false |
| Send a transaction when it is updated in a given state. | OnUpdated | state == "Approved" ? PushMaterialTransactionToErp("ERP-Main") : false |
In these examples ERP-Main stands for the name of your own push integration and Approved for a state value of your own workflow.
⚠️ Warning
- When an event occurs, only the first binding found for that event is run. Do not create two bindings for the same event.
- If the expression cannot be read (for example a missing quote or parenthesis) or a helper function fails, the error is logged and the user operation that raised the event fails.
- A push action whose integration is missing, inactive or not of the push type does not raise an error; it simply sends nothing.
Warnings and Error Messages
- Required Fields: "This field is required." is shown when Event or Action is left empty.
- Invalid Expression: An expression that cannot be parsed, or that calls an unknown function, causes the operation that raised the event to fail with an error.
- Binding Not Found: Editing or deleting a binding that another user has already deleted fails.
User Tips and Best Practices
- Start From the Defaults: Copy the expression of a default binding and change only its parameters.
- Use Exact Names: State values, state categories and integration names are compared as written; check them against the state and integration definitions.
- Keep Conditions Simple: Use the record fields and helper conditions; complex logic is harder to maintain and test.