AIML Docs

Action Elements

Elements for executing actions and modifying state

Action Elements

Action elements are used to perform operations and modify state within your workflow.

Available Elements

Assign

The <assign> element modifies data model values. Use it to update state, increment counters, or append to arrays.

Log

The <log> element outputs messages for debugging and tracing. Essential for development and troubleshooting.

Script

The <script> element executes JavaScript code. Useful for complex logic and computations.

Cancel

The <cancel> element cancels delayed events. Important for cleanup and workflow control.

Common Use Cases

  1. State Management

    <assign location="state.count" action="increment" />
  2. Debugging

    <log label="Debug" expr={({state}) => `Current state: ${state.status}`} />
  3. Complex Logic

    <script>
      const result = performCalculation(state.data);
      _dataModel.setValue('state.result', result);
    </script>
  4. Event Control

    <cancel sendid="reminder" />

Best Practices

  1. State Modifications

    • Use assign for simple state updates
    • Use script for complex calculations
    • Validate data before modifications
    • Keep state changes atomic
  2. Event Handling

    • Cancel delayed events when appropriate
    • Handle errors gracefully
  3. Debugging

    • Use log elements strategically
    • Include relevant context in logs
    • Consider log levels
    • Clean up debug logs in production
  4. Code Organization

    • Keep scripts focused and modular
    • Document complex operations
    • Use meaningful identifiers
    • Follow consistent patterns

See Also

On this page