Triggers

This section introduces and describes all possible ways of how an action execution can be triggered.

Manual trigger

The easiest way to trigger an action run is by executing it manually in the action editor. This is of course only possible in edit-mode and not when using a deployed app in the workspace. You can run an action manually by hitting the "Run"-button in the top-right corner of the action editor in the bottom panel. The result of the execution will be displayed in the :

Running an action manually is only possible for actions that have no unsaved changes. Until changes are saved, you will only see the "Save"-button in the top-right. After saving the action changes, the "Run"-button appears and allows to trigger the updated action.

Programmatic trigger

All actions are available as variables in JavaScript actions (learn more) and expose a trigger function, which allows to run the particular action. This function returns a Promise that resolves to the return value of the action, or is rejected with a potential error that occurred.

All JavaScript actions are async by default, which means that you can use await anywhere, including when triggering other actions. With that in mind, an example of triggering an action programmatically might look as follows:

// Assuming that "fetchProducts" is a REST action fetching products from an API.
const products = await fetchProducts();
productTable.setData(products);

Of course, you may also trigger other JavaScript actions, and the resulting Promise will resolve to the return value of that action.

Since the trigger function returns a Promise, you may trigger multiple actions at the same time, by for example using Promise.all:

const results = await Promise.all([
    fetchProducts(),
    fetchComments(),
    fetchQuantities()
]);

Event properties

Components are able to react to UI events, like clicking a button or focusing a text input field. These events can trigger actions, which is configured by assigning these actions to event handler properties. Usually, this is done by selecting an action in the dropdown for the particular event property:

The associated action will be triggered every time the particular UI event occurs.

When an action has been selected for an event property, you will see a "crosshair" icon next to the property label. Clicking on that icon will conveniently open the action editor in the bottom panel and focus the selected action.

Scheduled execution

Actions can be configured to run automatically based on a given schedule. You can access these trigger settings by clicking on the "Trigger" tab in the action configuration:

The following settings can be managed there:

  • Run action at page load: Setting this trigger will execute the action when the app is loaded. It is therefore similar to running JavaScript code on page load in traditional web engineering.

  • Run action periodically: With this trigger, an action can be configured to run in a specific interval, provided in milliseconds. Please note that this setting automatically includes running the action at page load, i.e. the action will run at page load, and then every time after the given amount of milliseconds. In this regard, the behavior differs from the native behavior of setInterval in JavaScript.

  • Minimum action delay: With this setting, you can configure the minimum amount of time that must have passed between two executions of an action. Executions that are triggered earlier than that are not cancelled, but postponed in a queue until the given amount of time has passed. See this example in which three fast clicks lead to delayed execution of an action:

Please familiarize yourself with the following potential pitfalls and details to be aware of:

In case both periodic execution as well as minimum delay are configured, you need to make sure that the periodic interval in milliseconds is not less than the minimum delay. Otherwise, more and more action executions will queue up and ultimately lead to failure.

A too small periodic interval can lead to a similar effect of an increased queue size, e.g. in case the interval is smaller than the average execution time of an action. Make sure you set sensible interval timings to prevent that.

An action is never executed more than once in parallel. Please refer to this documentation to learn more.

Last updated