- Release notes
- Getting started
- Installation
- Configuration
- Integrations
- Authentication
- Working with Apps and Discovery Accelerators
- AppOne menus and dashboards
- AppOne setup
- TemplateOne 1.0.0 menus and dashboards
- TemplateOne 1.0.0 setup
- TemplateOne menus and dashboards
- TemplateOne 2021.4.0 setup
- Purchase to Pay Discovery Accelerator menus and dashboards
- Purchase to Pay Discovery Accelerator Setup
- Order to Cash Discovery Accelerator menus and dashboards
- Order to Cash Discovery Accelerator Setup
- Basic Connector for AppOne
- SAP Connectors
- Introduction to SAP Connector
- SAP input
- Checking the data in the SAP Connector
- Adding process specific tags to the SAP Connector for AppOne
- Adding process specific Due dates to the SAP Connector for AppOne
- Adding automation estimates to the SAP Connector for AppOne
- Adding attributes to the SAP Connector for AppOne
- Adding activities to the SAP Connector for AppOne
- Adding entities to the SAP Connector for AppOne
- SAP Order to Cash Connector for AppOne
- SAP Purchase to Pay Connector for AppOne
- SAP Connector for Purchase to Pay Discovery Accelerator
- SAP Connector for Order-to-Cash Discovery Accelerator
- Superadmin
- Dashboards and charts
- Tables and table items
- Application integrity
- How to ....
- Working with SQL connectors
- Introduction to SQL connectors
- Setting up a SQL connector
- CData Sync extractions
- Running a SQL connector
- Editing transformations
- Releasing a SQL Connector
- Scheduling data extraction
- Structure of transformations
- Using SQL connectors for released apps
- Generating a cache with scripts
- Setting up a local test environment
- Separate development and production environments
- Useful resources
Process Mining
Example: Creating a Python Script
This example explains how to interface the UiPath Process Mining platform with external Python scripts to implement external data processing.
A Python script is created which:
- takes as input a
.CSV
file, to be specified on its command line as the sole required argument, - multiplies the Amount value by two,
- writes the result to its standard-output channel.
The generic script datasource requires handlers for all external processes that you want to run.
Follow these steps to add a generic script handler.
Step |
Action |
---|---|
1 |
Go to the Superadmin Settings tab. |
2 |
Add a field
GenericScriptHandlers with as value an object with one key, “py”, which has as value the path to your python executable. For example:
|
3 |
Click on SAVE. |
Start with creating a minimal script which does not yet do any data processing. This script will be used to verify that your python setup is working, and that your script is being called from the UiPath Process Mining platform.
This example script shows how to generate output that will appear in the script execution log, and how the exit code of a script influences the behavior of the UiPath Process Mining platform.
Step |
Action |
---|---|
1 |
In your favorite editor, start a blank text file. |
2 |
Enter the following text:
Note: The
debug(“Hello world!”) command is an example of how to use the standard error channel to output messages and debug output.
|
3 |
Save the text file as
script.py .
|
4 |
Upload the
script.py file to your workspace.
|
This script only prints a “Hello world!” message. The script interface uses standard output for data communication from the script to the UiPath Process Mining platform. If you want to include status messages in your script, you should write them to standard error instead.
Next, set up a datasource table in the app which will call the script. Start with some dummy data, since your script will not yet process the data. At this stage, it will be verified that the script is executed as expected, i.e. that you can see the “Hello world!” message.
Step |
Action |
---|---|
1 |
Open the app in your development environment. |
2 |
Go to the Data tab and create a new Connection string table. |
3 |
Rename the
New_table to PythonExample .
|
4 |
Right click the
PythonExample table and select Advanced > Options….
|
5 |
In the Table Options dialog, set the Table scope to Workspace. |
6 |
Double click on the
PythonExample table to open the Edit Connection String Table window.
|
7 |
Enter the following as Connection string: ``'driver={mvscript |
8 |
Enter the following as Query: ``''
The “#10” in the inputData example indicate new-line characters. I.e. we define the following dummy CSV data:
|
9 |
Click on OK. |
10 |
Click on YES. |
The table refresh fails, and in the error log you should see the “Hello World!” message
The location of the script file is determined by the table scope. This can be set to either Server or Workspace, or None. If set to None, the path to the script file is absolute. If it is set to Server or Workspace, the script’s location is interpreted as a relative path.
.CSV
format later on so that the python script can read it in.
For this example, we have an application with the a Cases table and an Events table. See illustration below.
Follow these steps.
Step |
Action |
---|---|
1 |
Create a new Global table,
PythonInputData .
|
2 |
Add a new expression attribute,
PythonInputData_Amount .
|
3 |
Set the Type to Lookup. |
4 |
Set the Input table to Cases_base. |
5 |
Set the expression to
listtojson(text(double(records.Amount))) .
|
6 |
Set the expression level to root. |
7 |
Click on OK. |
8 |
Add another lookup expression attribute, for the Case_ID. Set the expression to
listtojson(text(double(records.Case_ID))) .
|
csvtable()
function will be used to transform the data into .CSV
format, which expects a list of (text) records.
listtojson()
function requires its input to be of type text, the format of the records in the resulting CSV file depends on the type of
the selected attribute (in this case, Amount is of type Currency), and the currently active display format. Here the currency type is converted to double, to make it easier to parse the
records later in the python script.
In your text editor, update the script.py file with the following code.
#!/usr/bin/python
import csv
import sys
def debug(message):
sys.stderr.write(message)
# Read the CSV header. This is used so that the script will output the fields
# in the same order that they were read in. This step is optional.
column_order = [];
with open(sys.argv[1]) as csv_file:
reader = csv.reader(csv_file, delimiter=';')
column_order = next(reader)
# Process the input file
with open(sys.argv[1]) as csv_file:
reader = csv.DictReader(csv_file, delimiter=';')
# Construct the output writer.
writer = csv.DictWriter(
sys.stdout,
column_order,
delimiter=';',
restval='',
quoting=csv.QUOTE_ALL
)
writer.writeheader()
for row in reader:
# Get data from row
case_id = row['Case_ID']
amount = int(row['Amount'])
# Do computation
amount = amount * 2
# Write results
writer.writerow({'Case_ID': case_id, 'Amount': amount})
# Exit indicating success
exit(0)
#!/usr/bin/python
import csv
import sys
def debug(message):
sys.stderr.write(message)
# Read the CSV header. This is used so that the script will output the fields
# in the same order that they were read in. This step is optional.
column_order = [];
with open(sys.argv[1]) as csv_file:
reader = csv.reader(csv_file, delimiter=';')
column_order = next(reader)
# Process the input file
with open(sys.argv[1]) as csv_file:
reader = csv.DictReader(csv_file, delimiter=';')
# Construct the output writer.
writer = csv.DictWriter(
sys.stdout,
column_order,
delimiter=';',
restval='',
quoting=csv.QUOTE_ALL
)
writer.writeheader()
for row in reader:
# Get data from row
case_id = row['Case_ID']
amount = int(row['Amount'])
# Do computation
amount = amount * 2
# Write results
writer.writerow({'Case_ID': case_id, 'Amount': amount})
# Exit indicating success
exit(0)
Follow the steps below.
Step |
Action |
---|---|
1 |
Upload the new script to the Workspace, overwriting the existing file and go back to the application. |
2 |
Right click on the
PythonExample table and select Edit….
|
3 |
Modify the
inputData parameter of the query string for the PythonExample table:
See illustration below. |
4 |
Click on OK. |
5 |
Click on YES (2x). |
6 |
Click on OK. |
PythonExample
table now has two datasource attributes, Amount and Case_ID. See illustration below.
Inspecting the Amount attribute reveals that all amounts have been multiplied by two. See illustration below an example of the output generated by the python script.