# ION Actions

ION Actions allows you to define, manage, and automate business rules that govern your manufacturing processes directly within ION, leveraging the power and flexibility of GraphQL. Actions enable users to create, edit, update, or delete rules that determine workflow behaviors, enforce data validation, and manage conditions for status transitions.

### Key Action Fields

Each Action consists of key attributes that define its behavior and purpose:

* **Title:** Clearly identifies the Action's intent, appearing in toast notifications and serving as an internal reference for logging and tracking purposes.
* **Context:** Contains all necessary data used within the Action's script. This may include details such as model attributes, user roles, and specific issue details, structured as a JSON string for easy integration within GraphQL.
* **Code:** A Python-based script executed whenever the Action is triggered. This script defines the logic, conditions, and behaviors enforced by the Action. If conditions specified in the code are not met, a ValidationError is triggered.
* **Target:** Specifies the object or entity you wish to control and monitor for changes. The target is selected from a dropdown list during the initial creation of an Action.
* **Event:** Determines when the Action's Python code is evaluated. You can choose from UPDATE, CREATE, or DELETE events based on when you want the Action to execute in response to changes in the target.

Use cases for Actions include:

* Controlling when and how statuses within workflows can be updated or progressed.
* Ensuring critical fields are filled out before proceeding in a process.
* Validate that certain conditions are met before building critical hardware.
  * Example: making sure parts are flight worthy before installation.

### Actions Statuses

Below is guidance on creating and managing Actions effectively:

* **Enabled:** Actions in this status are live and actively enforced throughout your organization's production workflows. Newly created actions set to enabled will immediately influence workflow behaviors based on their conditions.
* **Disabled:** Actions in this status are not evaluated or enforced. Disabling Actions allows safe testing and refinement without disrupting live workflows, providing flexibility to toggle Actions between enabled and disabled states as needed.

Remember, you must enable rules within your organizational settings before using Actions to automate and enforce your processes. To do so you can follow the following instructions:

### Turn rules on in your environment: <a href="#id-2.-turn-rules-on-in-your-environment" id="id-2.-turn-rules-on-in-your-environment"></a>

First, rules must be enabled in your organization settings in order to use them.

Check that the rules are enabled with the below query:

```
{
  me {
    organization {
      id
      _etag
      settings {
        rules {
          enabled
        }
      }
    }
  }
}
```

If they are not, enable them with this mutation:

<pre><code><strong>mutation UpdateOrganization($input: UpdateOrganizationInput!) {
</strong>  updateOrganization(input: $input) {
    organization {
      settings {
        rules {
          enabled
          errorState
          errorStateMessage
        }
      }
    }
  }
}
</code></pre>

With the following input variables (retrieve the `etag` from the first query):

```
{
  "input": {
    "id": <populate from first query>,
    "etag": "<populate from first query>",
    "settings": {
      "rules": {
        "enabled": true
      }
    }
  }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://manual-v2.firstresonance.io/os/ion-actions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
