Python connector methods
Summarize
Summary of Python connector methods
The Python connector methods in RPA Desktop Design Studio enable ServiceNow customers to execute custom Python scripts or files within automation workflows. This capability allows integration of Python logic such as calculations, data processing, or custom functions directly into robotic process automation (RPA) tasks.
Show less
Prerequisites
- Proper configuration of the Python connector is required before use.
- Users should be aware of the limitations related to Python scripting within the connector.
- A compatible Python version must be installed on the environment running the scripts, especially for local execution.
Key Methods
Execute Method
This method runs Python scripts or functions that have been set up and configured within the Python connector interface. Key steps include:
- Selecting the configured Python class and method, or selecting standalone functions.
- Validating the selection, which generates a data output port to capture the script’s return value.
- Testing the execution directly from the design interface.
The Execute method returns the script output as a string via a data output port named "Result."
InvokeScript Method
This method executes Python scripts directly on the local machine by specifying the script file path and command-line arguments. Important points include:
- The Python file must exist at the provided path and run error-free.
- The command string mimics command prompt usage, e.g.,
python "C:\path\script.py"orpy -3 "C:\path\script.py". - Multiple arguments can be passed separated by spaces.
- The output of the script execution is returned as a string through a data output port.
Practical Example
A sample Python script demonstrates typical usage, including:
- Top-level functions for greeting a user and returning current time.
- A Calculator class with methods for addition and multiplication.
- A main execution block that runs all defined functions and methods in sequence.
This example highlights how users can organize their Python code for use with the connector methods, supporting both procedural functions and object-oriented classes.
Benefits for ServiceNow Customers
- Seamlessly incorporate Python scripts into RPA workflows for enhanced automation capabilities.
- Utilize both pre-configured Python methods and direct script invocation to suit different automation needs.
- Receive script outputs in a standardized manner, enabling further use within ServiceNow RPA processes.
Execute custom Python scripts or files as part of an automation workflow by using the methods of Python connector in RPA Desktop Design Studio.
Prerequisites for using the Python connector methods
Configure the Python connector. For more information, see Configure the Python connector.
Familiarize yourself with the limitations of Python script. For more information, see Limitations of Python script in Python connector.
Execute
Executes Python scripts set up in the configuration window. Before executing the method, you must configure the connector. See Configure the Python connector.
- Select the component and click the method settings icon (
) or double-click the component head bar.
- From the Classes list, select the class defined during the configuration of the Python connector.
For example, Math.
- From the Methods list, select the method defined during the configuration of the Python connector.
For example, add.
- Select the Show Functions check box and select a function from the Functions list.
Functions are those methods that are not written within a class. For example, banner.
Figure 1. Show Functions check box Figure 2. Function in Execute Method - Click Validate.
- Click OK.
A Data Out port (Result) is created to return the output.
- To test the method, right-click the Execute method and select Run From Here.
| Parameter | Description | Data port type | Data type |
|---|---|---|---|
| Result | Returns the output of the script. |
Data Out | String |
InvokeScript
Runs the Python script on local computers and gets the output. Ensure that the Python file is available in the file path provided.
Ensure that a Python version is installed on your machine. You must ensure that the Python script is running without errors.
| Parameter | Description | Data port type | Data type |
|---|---|---|---|
| Script | Returns the output of the script. The command specified in the Script parameter for execution via the InvokeScript component is same as the command line that is used to run in a command prompt. Provide a file path for the Python script. For example, python "C:\Users\abel.tutor\Downloads\utility_runner.py" For example, py -3 "C:\Python testing\project1\main.py" Abel it has <python with version> <python file path> <arguments> format. For adding multiple arguments, use space. Example of a Python script that greets the user, returns current time, and performs calculations of
add and multiply.
|
Data In | String |
| Return | Output of the script that is returned. |
Data Out |