callScript
Execute a Python script for each row in a table, where the script does the processing of the values in the table that are passed as arguments.
The script must be uploaded to the LogicHub (drag and drop script file to Automations > Scripts).
Operator usage in easy mode
Click + on the parent node.
Enter the Call Script operator in the search field and select the operator from the Results to open the operator form.
In the Input Table drop-down, enter or select the table containing the data to run this operator on.
In the Script Name drop-down, select the name of the script.
In the Args drop-down, select one or multiple column names to use as arguments for the script.
In the Time between Calls field, enter a value in seconds, minutes, hours, days, or weeks.
Click Run to view the result.
Click Save to add the operator to the playbook.
Click Cancel to discard the operator form.
Usage details
LQL Command
callScript(inputTable, scriptName, args, timeBetweenCalls)
Input:inputTable
: Table containing the data to run this operator on.scriptName
: Name of the script as appear on the Scripts pageargs
: Column names to use as arguments for the scripttimeBetweenCalls
: Time between calls
Output:
new lhub_id
, exitCode
, error
and output
for each row. If the output is a list of JSON objects (e.g. rows), the output explodes the array into rows and extracts JSON values in the JSON objects into new columns.
args
are the columns names (such as ["user", "accessCode"]). From the script they are accessed using sys.argv[1] and so on. To produce output to the table, you must print the result. See examples below for more information.
Example 1
Table = "users"
firstName | lastName | emailAddress |
---|---|---|
Tom | Toms | tom@devo.com |
Create the following Python script file, save it as scriptOne.py, then drag and drop this file to Automations > Scripts page.
Python
import sys
# sys.argv[1] is value of firstName column
# sys.argv[2] is value of lastName column
# sys.argv[3] is value of emailAddress column
# ordering is important
email = sys.argv[3] # tom@devo.com
work = email.split('@')[1].split()[0] #devo
print("%s %s works at %s" % (sys.argv[2].upper(), sys.argv[1], work.upper()))
Create a computation step and in the LQL write following line.
LQL command
callScript(users, "scriptOne.py", ["firstName", "lastName", "emailAddress"], "1 s")
-- Note: arguments (columns) ordering are important, you need to remember which columns is at which index
Output
firstName | lastName | emailAddress | output | exitCode | error |
---|---|---|---|---|---|
Tom | Toms | tom@devo.com | TOMS Tom works at DEVO | Â | Â |
Example 2
If the script produces multiple rows for each row, you must print them as an array of JSON objects that will get populated into columns and rows.
Python
Output
firstName | lastName | emailAddress | output | FIRSTNAME | LASTNAME | EMAILADDRESS | length | exitCode | error |
---|---|---|---|---|---|---|---|---|---|
Tom | Toms | JSON object | TOM | Â | Â | 4 | Â | Â | |
Tom | Toms | JSON object | Â | TOMS | Â | 9 | Â | Â | |
Tom | Toms | JSON object | Â | Â | 17 | Â | Â |
For 1 row, 3 rows were produced. Because each row has a different JSON schema.
FIRSTNAME, length
LASTNAME, length
EMAILADDRESS, length
The operator did the union of all field names, and produced new columns for each field name.