Code Block documentation

Overview

The Code Block scenario step enables the execution of code using Jinja2 templates.
This functionality facilitates the parsing and modification of variables, as well as the implementation of custom logic.

Exits

Each step within the scenario must conclude with an exit. Exits are created by clicking the "+" button, where each exit
requires a label and a reference. The label is displayed in the scenario editor, while the reference is utilized within
the code to specify the exit.

  • Maximum Exits: Up to 10 exits can be added

Exit selection

To designate an exit within the code, utilize the set_exit('exit_id') function, replacing exit_id with the reference of the desired exit.

    {{ set_exit('sortie_b') }}
    {% set var_str = "abc" %}

Note: The set_exit() function does not halt execution, it only sets the exit for the conclusion of the execution.
In the example above, the variable var_str will still be updated to hold the value "abc".

Tests

During the development of the Code Block, it is highly recommended to utilize the built-in Test button for testing
purposes. This button opens an input box where variables that were previously set in the scenario can be defined.
Once ready, proceed by clicking the Run test button.

Test output

The test will return you the following values:

  • Exit taken: The reference of the exit, allowing verification of the logic.
  • Error logs: If any, to assist in debugging.
  • Updated variables values: All variables set in the template are displayed with their latest values.
  • Logs with timestamps: Refer to the Logs section for more details.

Logs

To help in debugging, Alcmeon has implemented a custom function in Jinja2 that allows for the addition
of logs within the code. Invoke the log() function to log data or text. These logs are displayed in test mode
once the test is executed.

Examples:

    {{ log("abc") }}
    {{ log(variable) }}

Note: This function operates exclusively in test mode. Logs are not retained when executed in "run" mode within the scenario.

Errors

In the event of an error during code execution, the bot will proceed with the "error" exit.
The most recent 50 errors can be exported from the scenario page by clicking on the box menu and selecting
"Export last 50 errors". This action generates an .xlsx file containing the necessary information to address the issue.


Custom filters

For data manipulation, we have implemented a list of filters. you can check the list here: https://developers.alcmeon.com/docs/jinja2-documentation-and-custom-filters-guide