Tools
The following blocks work as tools in scripts:
- Ungroup array
- Synchronizer
- Get system table
- Return data
- Execute script
- Filter
- Execute an instruction
Ungroup Array
The block splits an array into data packages. The subsequent blocks are executed as many times as there are elements inside the array. It simplifies working with arrays and allows you to use array elements as if they were variables.
The block has a single field to fill in — an array (select from the list of data obtained from previous blocks).
Example:
- Select an array in the Array field on the mapping panel and click Run test. The array data is displayed in the square brackets.
- The output contains the ungrouped data.
Synchronizer
The block allows you to split the script into independent parts that cannot access each other's data. It waits for the previous blocks to finish as many times as required for data collection, then triggers the subsequent blocks once. This helps to reduce the number of script executions and allows you to place all actions into a single script instead of multiple ones.
Get System Table
This block supplies ClickHouse with updated data from system tables.
Parameters of the block:
- Table
- Columns — you can select any number of columns. If none are selected, all columns are used automatically
- Sampling period start — this field is only displayed when selecting the
script_execution,script_event_history, orautomation_block_executiontables. Valid date/time values: no earlier than 24 hours from the current time. The date can be specified in the format YYYY-MM-DD / YYYY-MM-DD hh:mm:ss, or passed from previous blocks via visual mapping.
- A table must be selected; otherwise, the block cannot be tested, and the script cannot be published.
- To use this block, you need the System tables privilege.
Descriptions of system table fields available via this block are provided in the System Tables section.
Return Data
The Return data block returns data to the request source. It works with the triggers Manual start and Webhook triggers.
This block is used to return results from scripts that were run manually or via Webhook.
Block parameters:
- Request format (JSON/text)
- Returned data
If the request format is Text, the returned data is specified manually or via visual mapping. If the format is JSON, the key must be entered manually, and the key value can be specified manually or via mapping.
In synchronous mode with the New event block (Webhook package), the status and data defined in Return data (if any) are returned immediately after script execution.
In asynchronous mode, to retrieve returned data, you need to wait for the Return data block to run and then execute the following GraphQL query in GraphiQL:
{
automation{
script{
execution_result(uuid:"5053bb30-3eed-469c-a60a-7b554198ceee"){
return_data
}
}
}
}
Where:
execution_result— the webhook identifier. To obtain it, you need to send a request to the webhook URLreturn_data— the returned data specified in the Return data block
To retrieve statuses when the New Event block from the Webhook package operates in asynchronous mode, you need to execute the GraphQL query shown below in the GraphiQL tool.
{
automation{
script{
execution_result(uuid:"5053bb30-3eed-469c-a60a-7b554198ceee"){
status
}
}
}
}
Where execution_result — webhook identifier. To obtain the identifier, send a request to the webhook address.
If multiple Return data blocks are added to the script, only the first one is executed and returns data.
If the script with the Return data block stops with an error or is terminated, the execution status information is returned to the source.
This block terminates script execution, so any blocks after it will not run.
Execute Script
This block starts the execution of a selected script.
Parameters:
- Script
- Expected fields (if they are defined in the selected script)
A parent script is a script that contains the Execute script block, which triggers the execution of a child script. After the block starts the child script, it waits until the child script fully completes and returns data to the parent script.
- The child script must end with a Return data block.
- Only scripts that are located in the same workspace as the parent script can be executed.
- When testing the block or the entire parent script, the draft version of the child script is executed. When the parent script is activated, the published version of the child script is executed.
When using this block we recommend:
- Do not create looping scenarios where an Execute script block calls a child script that itself contains an Execute script block calling the parent script.
- Stop resource-heavy child scripts manually if needed, since stopping the parent script does not automatically terminate the child script.
The block returns information about the execution of the child script:
- If the child script completes successfully but does not Return data, the parent script only receives confirmation that the child script was executed
- If an error occurs in the child script, the parent script receives the error details and stops execution
Filter
The block allows you to configure script logic and direct it along a specific branch after checking an indicated condition.
Parameters:
- Fields for comparison
- Condition
The block does not Return data; it only filters it.
To configure the script:
- Specify the comparison objects in the corresponding fields.
- Select the filter condition from the dropdown list.
- Click Run test to test the script.
To add multiple conditions within one group, use the And button.
To create an additional filter group, use the Or button.
To delete a filter group, click Delete.
You can direct the script along multiple branches:
- To add several conditions and branch the script depending on whether the data meets those conditions, add multiple Filter blocks
- To branch the script with data obtained after checking one condition, create as many branches from the Filter block as needed
Different data types support different conditions:
| Data Type | Available Conditions |
|---|---|
| String | - Starts with - Does not start with - Ends with - Does not end with |
| String, array | - Contains - Does not contain |
| All data types | - Exists - Does not exist - Equals - Does not equal |
| String, Integer, Date, Date and time | - Greater than - Less than - Greater than or equal to - Less than or equal to |
| Date, Date and time | - Lately |
| Boolean | - is true - Is false |
| String, Date, DateTime, Number, Array of numbers | - Empty - Not empty |
If the selected type of condition cannot be applied, an error occurs.
Execute an Instruction
This block receives an instruction, which can be created manually or via the Send message block from the LLM package, and performs actions using the functions of the following blocks:
In the block parameters, specify the instruction in JSON format manually or using mapping. The Instruction field can also take the string value break. The string break is a command that stops the execution of the Execute an instruction block.
The instruction is passed in JSON with the following fields:
Action— the type of block whose function should be executedFields— the structure of fields for the block type being executed (optional fields can be omitted)Index— the execution sequence number, which must be incremented by the LLM
Block behavior:
- The block analyzes the input. Allowed values:
- JSON
- The string
break(case-insensitive)
- If the input is
break, the block finishes execution with an empty result. The script stops after this block - If the input is JSON, the block validates the block type, fields, and execution number
- If validation is successful, the block executes the function of the specified block type using the given parameters and execution context
The maximum number of Execute an instruction block runs in a single cycle is 30.
During a single run, the Execute an instruction block can only execute functions of one type of the blocks. Attempting to process multiple datasets or invoke functions of different blocks in a single run may cause a failure due to data inconsistency.
You can find examples of instructions below.
Execute script:
{
"action": "execute_script",
"key": "",
"": "",
"": ""
}
Send a message:
json { "action": "query", "query": "", "model": "", "temperature": }
Send an HTTP request:
json { "action": "http_request", "url": "", "method": "", "body": "" }
Send an email:
json { "action": "send_email", "to": "", "subject": "", "text": "", "format": "" }
Insert rows into a table:
json { "action": "insert_rows", "table": "", "rows": [ { "": "", "": "" }, { "": "", "": "" } ] }
Return data:
json { "action": "return", "value": "", "format": "" } ```
Was the article helpful?