Invoke a custom script

Updated at:

1. Component overview

Note

Prerequisites: None

You can use this component to write and run Python scripts.

2. Inputs

Note

See the help text for each input parameter in the component pane of the application flow editor.

3. Outputs

Note

See the help text for each output parameter in the component pane of the application flow editor.

4. Component examples

4.1 Example 1: Hello world

  1. In the Script to execute field, enter the expression `print("Hello World")`.

  2. Use the default values for the advanced options.

  3. After the flow runs successfully, "Hello World" is automatically printed to the log pane.

4.2 Example 2: Use flow variables

Note

In the Invoke Custom Script component, you can use variables that were defined earlier in the flow directly in your Python script. You can read the values of these variables and assign new values to them.

When you assign values in a custom script, avoid assigning incorrect data types. For example, assigning a string such as "abc" to a numeric variable may cause subsequent steps to fail.

  1. Add two variables, `v_param1` and `v_result`. Set the value of `v_param1` to 1.

  1. In the Invoke Custom Script step, add 1 to `v_param1` and assign the result to `v_result`.

Note

Assign the result of the custom script to a variable that is already defined in the flow, such as `v_result` in this example. If you assign the result to a new, undefined variable, subsequent steps in the flow cannot use it.

For example, if you change the custom script to `sum_result = v_param1 + 1`, you cannot select `sum_result` from the variable drop-down list in subsequent steps.

  1. Print the value of `v_result`. The output is 2.