runScriptV2

Run a function of an python script for each row of the input table.

Run a Python script that contains a function on each row of the parent table.

Operator Usage in Easy Mode

  1. Click + on the parent node.
  2. Enter the Run Script operator in the search field and select the operator from the Results to open the operator form.
  3. In the Input Table drop-down, enter or select a table containing the data to run this operator on.
  4. In the Choose Script drop-down, enter or select the name of the script in which function exists.
  5. In the Choose Action drop-down, enter or select an action that will be executed for each row.
  6. In the Explode Fields, choose to explode the output fields by clicking on True or False options.
  7. Click Run to view the result.
  8. Click Save to add the operator to the playbook.
  9. Click Cancel to discard the operator form.

Usage Details

runScript(inputTable, scriptName, entryFunction, explodeFields)

Input:
inputTable: Table containing the data to run this operator on.
scriptName: Name of the Python script that contains the function.
entryFunction: The function to be executed for each row. Use parent column names as function arguments.
explodeFields: Whether to explode the output fields (true) or not (false).

output:
entryFunction runs on each row of the parent table.
if explodeFields is false, the results of entryFunction appear in a result column.
if explodeFields is true, entryFunction returns a dictionary. The keys of dictionary become columns of the output table.
if explodeFields is true and entryFunction returns something other than the dictionary, the result is shown in the other_field column.

Examples

script

from lhub_integ import action

# Functions annotated with @action can be called in runScript automation
# Try using the actions defined below by mapping columns to the parameters and hit Run

@action
def sum_and_product(column1, column2):
	# Return a dictionary to create multiple columns in the output table with explode set true
	# If explode is set to false, you will get the dictionary as json in `result` column
	return { "sum" : column1 + column2, "product" : column1 * column2 };

@action
def double(column1):
	# Return a non-dictionary type to get the value in an `other_field` column
  return column1 * 2;

input

val1val2
35

Example 1

command

runScript(inputTable, 'operationScript.py', 'sum_and_product(val1, val2)', 'true')

output

sumproductother_fieldexit_code
8150

Example 2

command

runScript(inputTable, 'operationScript.py', 'sum_and_product(val1, val2)', 'false')

output

resultexit_code
{"sum": 8, "product": 15}0

Example 3

command

runScript(inputTable, 'operationScript.py', 'double(val1)', 'true')

output

other_fieldexit_code
60

Example 4

command

runScript(inputTable, 'operationScript.py', 'double(val1)', 'false')

output

resultexit_code
60

© Devo Technology Inc. All Rights Reserved.