# Actions

An action is a block of one or more logical operations, for example to navigate in an app, or to update data. Actions are in many ways equivalent to a function or method in traditional programming. Actions are a key element of building *logic* in Appfarm Create, in conjunction with [conditions](https://docs.appfarm.io/reference/platform-concepts/conditions) and [functions](https://docs.appfarm.io/reference/platform-concepts/functions), in order to tie the [UI](https://docs.appfarm.io/reference/apps/ui) and [data](https://docs.appfarm.io/reference/apps/data) together. Actions are also an element of [services](https://docs.appfarm.io/reference/services).

{% hint style="info" %}
**Good to know**

Actions in apps are run locally in the browser while [actions in services](https://docs.appfarm.io/services#actions) run on the server.
{% endhint %}

The logical operations you can add to an action are called *action nodes*. Appfarm Create features a built-in [library of action nodes](https://docs.appfarm.io/library/action-nodes) that can be dropped into an action, each with customizable properties. These include [if statements](https://docs.appfarm.io/library/action-nodes/if) and [foreach loops](https://docs.appfarm.io/library/action-nodes/foreach) as well as [data](https://docs.appfarm.io/library/action-nodes/create-object) [operations](https://docs.appfarm.io/library/action-nodes/update-object) and advanced functionality such as [generating PDFs](https://docs.appfarm.io/library/action-nodes/generate-document) and [sending SMS](https://docs.appfarm.io/library/action-nodes/send-sms).&#x20;

As you add action nodes in sequence within an action, you construct the logical flow of what should happen under which circumstances. When the action is triggered, the action nodes will be run in order from top to bottom.

{% content-ref url="../../library/action-nodes" %}
[action-nodes](https://docs.appfarm.io/library/action-nodes)
{% endcontent-ref %}

## Triggers

An action is typically triggered by user behavior via an [event handler](https://docs.appfarm.io/reference/platform-concepts/event-handlers), such as **On Click**. In this case, a *Save* button in a dialog might persist the data entered into a runtime data source and close the dialog. Another common trigger is the [On App Load](https://docs.appfarm.io/reference/app-settings#event-handlers) event handler.

Actions can also be triggered by other actions, using Run Other Action. This enables you to create an action once and re-use your logic across your app. Finally, actions can be triggered automatically using [timers](https://docs.appfarm.io/reference/app-settings#timers).

## Debugging

Actions in an app are [listed in Developer tools](https://docs.appfarm.io/appfarm-client/developer-tools-for-apps#actions), which provides an easy way to test and debug actions using breakpoints. Any errors that occur will be reported in the [client logs](https://docs.appfarm.io/appfarm-client/developer-tools-for-apps#logs).

The [Log to Console action node](https://docs.appfarm.io/library/action-nodes/log-to-console) can be used to print data to the logs and `console.log` statements in [functions](https://docs.appfarm.io/reference/platform-concepts/functions) will also be output.

Action nodes lacking values for required properties will be highlighted with a red indicator in the Action Editor in Create. [App Health](https://docs.appfarm.io/reference/apps/app-health) will also highlight action nodes that lack values for required properties.

## Properties

{% hint style="success" %}
**Best practice**

Use a verb when naming an action, for example `Save event`. This provides a quick description of what the action does. By including the object class *event*, it's easy to filter on actions which affect a specific object class.

Another alternative is to use the object class as a prefix, for example `Event: Save`. Since the list of actions is sorted alphabetically this has the benefit if listing all *Event*-related actions together.
{% endhint %}

<table><thead><tr><th width="225">Property</th><th>Description</th></tr></thead><tbody><tr><td><strong>Name</strong></td><td>A descriptive name.</td></tr><tr><td><strong>Description</strong></td><td>A longer description of the service. For your own reference.</td></tr><tr><td><strong>Pause Render</strong></td><td><p>Pause UI updates while the action is running.</p><p></p><p>By default, when an action is triggered from the UI, for example by clicking a button, any UI changes triggered by the action will run as they occur. This can result in a poor user experience, or degraded performance. By enabling pause render, any UI changes will not occur until the action has finished running.</p></td></tr><tr><td><strong>Skip Render</strong></td><td><p>Do not update the UI after the action is finished. See <strong>Pause Render</strong>.</p><p></p><p>As an example, say you have enabled skip render and are displaying an App Variable with the value <code>1</code>. If the action updates the value to <code>100</code>, the UI will continue to display <code>1</code> even after the action has finished running.</p></td></tr><tr><td><strong>Parallel Execution</strong></td><td><p>Allow the action to fire multiple times in parallel.<br><br>By default, an action will not run if the same action is already running for that user. This is to prevent the action firing multiple times when a user double clicks a button, for example.</p><p></p><p>Only enable parallel execution when needed and only on simple actions without heavy data processing or external API calls. One common case is when using <strong>On Hover Start</strong> and <strong>On Hover End</strong> to set a runtime boolean property to control visibility or styling in the UI.</p></td></tr><tr><td><strong>Action Params</strong></td><td>Add <a href="#action-parameters">action params</a>.</td></tr></tbody></table>

### Action params

An action param defines a variable that can be used to pass a value into the action when it's triggered. Within the action, the value can be referenced via Context params which are available in [conditions](https://docs.appfarm.io/reference/platform-concepts/conditions), [filters](https://docs.appfarm.io/reference/platform-concepts/filters), and [functions](https://docs.appfarm.io/reference/platform-concepts/functions).

Action params enable you to reduce the number of actions in an app. You can create actions with more generalized functionality, as the action can be provided context each time it's triggered. One frequent example is an action to change the views in an app. The action requires an action param with the data type `View` and a single action node, [Navigate](https://docs.appfarm.io/library/action-nodes/navigate), set to navigate to the value specified in the action param. From throughout your UI, as well as from within other actions, you can call this action and specify the view you wish to navigate to as the action param value.

<table><thead><tr><th width="232">Property</th><th>Description</th></tr></thead><tbody><tr><td><strong>Name</strong></td><td>A descriptive name.</td></tr><tr><td><strong>Data Type</strong></td><td>The type of data accepted as input for this parameter. See <a href="../../data-model/object-classes#data-types">object classes</a> for more information.</td></tr><tr><td><strong>Required</strong></td><td>Require that a value for this parameter is always specified when the action is triggered.</td></tr><tr><td><strong>Default Value</strong></td><td><p><em>Not available if Required is enabled.</em></p><p></p><p>Specify a default value to use in the case that a value is not provided when the action is triggered.</p></td></tr></tbody></table>
