Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents
minLevel1
maxLevel6
outlinefalse
typeflat
printablefalse

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.

...

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.

...

Code Block
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.

...

Code Block
import sys
fn = sys.argv[1]
ln = sys.argv[2]
ea = sys.argv[3]
print('[{"FIRSTNAME":"%s", "length":%d}, {"LASTNAME":"%s", "length":%d}, {"EMAILADDRESS":"%s", "length":%d}]'%(fn, len(fn), ln, len(ln), ea, ln(ea)))

Output

firstName

lastName

emailAddress

output

FIRSTNAME

LASTNAME

EMAILADDRESS

length

exitCode

error

Tom

Toms

tom@devo.com

JSON object

TOM

4

Tom

Toms

tom@devo.com

JSON object

TOMS

9

Tom

Toms

tom@devo.com

JSON object

tom@devo.com

17

For 1 row, 3 rows were produced. Because each row has a different JSON schema.

...