# How to Create and Maintain an Action in ActionJail (Administrator)

ActionJail allows you to quickly add your own logic without developing the platform core. This instruction will help you create a new action, edit it, clone or delete it, as well as organize the config and parameter input form.

---

## When It Will Be Useful
- You need to add a business rule or integration without changing the main code.
- You need to update the logic of an existing action after a process change.
- There is a typical action that is faster to copy and adapt.

---

## What's Important to Know
- **Action** — a JS script with its own system ID (`action_*`), configuration, and UI schema for parameters.
- **Action wizard** — 5 steps: Information → Code → JSON config → UI schema → Documentation.
- **System ID** — does not change after creation; used in scenarios.

---

## Before You Start
- [ ] You have a role with access to `Apps → ActionJail`.
- [ ] You have a description of the action logic and required parameters at hand.
- [ ] It is determined who will use the action in scenarios (for name and description).

---

## Step-by-Step Instructions
1. Open `Apps → ActionJail` and click `Add new action` — the wizard opens.
2. **Action Information**: specify the display name, check the system ID (`action_*`), add a short description of the purpose.
3. **Code**: paste or write JS logic; if needed, use AI generation for a draft.
4. **JSON config**: set launch parameters (keys, default values) so scenarios can pass data.
5. **UI schema**: add input fields (name, type, required, hint, default); this is what scenario users see.
6. **Documentation**: briefly describe what the action does, what parameters it expects, and a launch example.
7. Click `Complete` — the action appears in the list. For edits, open the action from the list, change fields, and click `Save`.
8. To clone, select an action → `Make a copy` — check the new system ID and save.
9. To delete, select an action → `Delete action` → confirm.
10. **Testing**: After saving, use the **Testing** section to test action execution with different parameters before using in scenarios.

---

## What Happens After
- A new or updated action is available in the list and can be used in scenarios.
- A clone is created with a new system ID, the original is not changed.

---

## How to Verify Everything Worked
- The action is displayed in the library and opens without errors.
- The system ID is unique and does not change during editing.
- UI schema fields are visible in the action parameter form in the scenario.
- **Testing section** is available in the action editor (for custom actions only) and allows testing execution with different parameters.

## Testing Actions

The **Testing** section allows you to test action execution before using it in scenarios. This helps verify that the action works correctly with different parameters.

### When to Use Testing
- After creating or updating an action code
- Before connecting an action to a scenario
- When debugging action logic
- To verify parameter handling

### How to Test an Action
1. Open an action from the list (custom actions only — system actions don't have testing).
2. Go to the **Testing** section (before Documentation).
3. Choose a test mode:
   - **Simple Mode**: Enter JSON parameters directly (e.g., `{ "param1": "value1" }`).
   - **Full State Mode**: Enter complete state structure (can be copied from Scenario Builder).
4. If parameters are missing, click **Add first parameter** to quickly create a test parameter.
5. Click **Test Action** — the action executes with provided parameters.
6. Review the result:
   - **Result**: The value returned by the action
   - **Logs**: System logs from execution
   - **Errors**: Any errors that occurred during execution
   - **Execution Time**: How long the action took to execute

### Test Modes

**Simple Mode**:
- Enter only the parameters your action needs (from `json_obj`).
- JSON editor auto-fills with default values from "Default JSON config" if available.
- Suitable for quick testing of action logic.

**Full State Mode**:
- Enter the complete `KwizbotEngine` state structure.
- Includes node, const, position, and other context.
- State can be copied from Scenario Builder for realistic testing.
- Shows hint: "This state can be copied to **Scenario Builder**".

### Tips
- If "Default JSON config" is empty, you'll see "Parameters absent" with an option to add the first parameter.
- Test with different parameter values to ensure robust handling.
- Check logs to understand action execution flow.
- Use Full State mode when testing actions that depend on scenario context.

---

## Other Ways
- Cloning instead of creating from scratch — faster for similar actions.
- AI generation of code/config/documentation — for drafts, but check manually.

---

## Related Instructions
- [Find an action in the list](/en/actionjail/how-to/filter-search-actions.md)
- [Clone an action](/en/actionjail/how-to/clone-action.md)
- [Actions Reference — complete reference for standard actions](/en/actionjail/reference/actions-reference.md)

