Invoke a custom script
1. Component overview
Prerequisites: None
You can use this component to write and run Python scripts.
2. Inputs
See the help text for each input parameter in the component pane of the application flow editor.
3. Outputs
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
In the
Script to executefield, enter the expression `print("Hello World")`.Use the default values for the advanced options.
After the flow runs successfully, "Hello World" is automatically printed to the log pane.
4.2 Example 2: Use flow variables
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.
Add two variables, `v_param1` and `v_result`. Set the value of `v_param1` to 1.
In the Invoke Custom Script step, add 1 to `v_param1` and assign the result to `v_result`.
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.
Print the value of `v_result`. The output is 2.