Understanding the pluggable RPA bot generator script
Starting from IBM Process Mining release 1.14.0, the application includes the capability of pluggable RPA Bot generation. Using this feature, you can create custom RPA bots for any vendor by providing a generator script that is written in JavaScript, and registering it as a vendor in IBM Task Mining. You must ensure to assign RPA scripts for each task in the activity for which you need to generate the bot.
Additional features of RPA bot generator script
The RPA bot generator script includes the following additional features:
-
In the bot generator script, you can specify the name and extension of the file that you want the system to generate.
-
You can create multiple files in a single execution of the script by providing multiple functions within the main script.
Accessing the sample pluggable RPA bot generator script
To download the sample pluggable RPA bot generator script template, see RPA bot generation on Github.
You must ensure that the pluggable Bot generator script is developed in JavaScript.
IBM Process Mining supports scripts that are written in ECMAScript 6 or earlier.
The downloaded template contains a sample bot generator script file
for UiPath. You can use this sample file to generate an XAML file that can be directly run in the UiPath Studio. The rule expressions in the file are generated in Visual Basic syntax.
Understanding the pluggable RPA bot generator script
You must name the main function on the pluggable RPA bot generator script as generateBot
and it must include three function arguments such as dataModel
, snippets
, and contextualData
.
function generateBot(dataModel, snippets, contextualData)
It is not necessary to use the argument names as provided in the sample template code. However, if you modify the argument name, then you must ensure to update the argument name at all occurrences in the entire script.
Go to the following topics to learn more about the arguments:
dataModel
The dataModel
argument is the first argument to the generator function and is injected as a JSON object by Process mining.
Example 1: The following example demonstrates the structure of a dataModel object.
{
"startNodes": [
"BTN1"
],
"endNodes": [
"BTN3",
"BTN6"
],
"transitions": [
{
"source": "BTN1",
"destination": null,
"rules": {
"BTNPLUS": {
"OR": [
{
"AND": [
{
"attribute": "productName",
"operator": "IN",
"value": "['A', 'B']"
}
]
},
{
"AND": [
{
"attribute": "amount",
"operator": "<=",
"value": "10749.0"
}
]
}
]
},
"BTNMINUS": {
"OR": [
{
"AND": [
{
"attribute": "amount",
"operator": ">",
"value": "10749.0"
}
]
}
]
}
}
},
{
"source": "BTNMINUS",
"destination": "BTN6",
"rules": null
},
{
"source": "BTNPLUS",
"destination": "BTN3",
"rules": null
}
],
"aliasToTasksMap": {
"ButtonOne": [
"BTN1"
]
},
"humanMandatoryInfo": [
{
"taskName": "BTN1",
"humanMandatory": false
},
{
"taskName": "BTN3",
"humanMandatory": false
},
{
"taskName": "BTN6",
"humanMandatory": false
},
{
"taskName": "BTNPLUS",
"humanMandatory": false
},
{
"taskName": "BTNMINUS",
"humanMandatory": false
}
]
}
This sample JSON object includes the following five main components, such as startNodes
, endNodes
, transitions
, aliasToTasksMap
, and humanMandatoryInfo
.
-
startNodes
This component lists the task names from which the execution must start. In a normal BPMN model, there is only one startNode, though there can be more.
If there are more than one
startNodes
, then the system considers it as an invalid scenario and ends the script execution with an error message. Similarly, if no nodes are listed instartNodes
, then the system ends the bot generation process and displays an error message. -
endNodes
This component lists one or more tasks that mark the end of a flow. When the execution reaches a task that is listed as
endNodes
, the system considers the bot execution as completed.The sample RPA generator script that is provided in this document, marks all such nodes with the
isFinal=true
attribute in the UiPath script generated. -
transitions
This object represents the transition of flow from the start to the end based on the BPMN. You can have direct transitions from one node to another and rule-based transitions.
Example 2: The following example demonstrates a direct transition from
BTNMINUS
toBTN6
. In other words, after running the code snippet ofBTNMINUS
, the automation provider selects the snippet ofBTN6
for execution.{ "source": "BTNMINUS", "destination": "BTN6", "rules": null }
Rule-based transitions do not include a direct transition from one node to another. Hence, the destination is always null. Instead, it includes one or more rules that define a condition to transition to the next node in the execution flow.
Example 3: In the following example, after running
BTN1
, the automation provider selectsBTNPLUS
only if the defined condition (productName IN ‘A’ or ‘B’ AND amount <= 10749.0
) is satisfied.{ "BTNPLUS": { "OR": [ { "AND": [ { "attribute": "productName", "operator": "IN", "value": "['A', 'B']" } ] }, { "AND": [ { "attribute": "amount", "operator": "<=", "value": "10749.0" } ] } ] } }
The rules are structured in a special format to easily traverse them. Every rule in a transition is a group of one or more
OR
expressions. EachOR
expression includes one or moreAND
expressions. The generator script must iterate over this structure to build the vendor-specific conditional expression equivalent to this expression.Logical operators
Table 1 describes the logical operators that you can use in the rules that are passed to the generator script from Process Mining.
Table 1. Logical Operators
Logical operator Description Usage Example IS
Equal to the value productAmt IS 123.45
IS NOT
Not equal to the value productAmt IS NOT 123.45
<
Less than the value productAmt < 123.45
>
Greater than the value productAmt > 123.45
<=
Less than or equal to the value productAmt <= 123.45
>=
Greater than or equal to the value productAmt <= 123.45
IN
Contains a value productAmt IN (123.45, 234.56, 345.67)
NOT IN
Does not contain a Value productAmt NOT IN (123.45, 234.56, 345.67)
INSIDE
Value in a range You can use the INSIDE operator to define various logical expressions.
- The expression,
productAmt INSIDE (100, 200)
indicatesproductAmt > 100 && productAmt < 200
. - The expression,
productAmt INSIDE [100, 200)
indicatesproductAmt >= 100 && productAmt < 200
. - The expression,
productAmt INSIDE [100, 200]
indicatesproductAmt >= 100 && productAmt <= 200
.
Conditional Expressions
Conditional expressions are generated based on the data type information that is derived from the contextual data details that are loaded to the script.
Contextual data from Process Mining can be of the following data types:
- string
- numeric
- integer
- long
- double
- date (according to Epoch timestamp)
Example 4: The Visual Basic expression for the rule generated in the UiPath Bot generator script (demonstrated in Example 3) is as follows:
<Transition.Condition>[({'A','B'}.Contains(productName)) Or (amount <= 10749.0)]</Transition.Condition>
- The expression,
-
aliasToTasksMap
The
aliasToTasksMap
component indicates a map that contains the alias names to tasks mapping (if any) represented in the process mining project. Currently, the generator does not use this component as the alias names used by the BPMN are converted to the original task names in the data model injected to the generator. Additionally, these names are maintained in the data model for any future references.The application restricts you from mapping multiple tasks with the same alias name for a Task mining project, as it prevents the application from fetching and assigning the correct RPA snippets to tasks while generating RPA Bots.
Example 5: You can define the
aliasToTasksMap
component as follows:"aliasToTasksMap": { "ButtonOne": [ "BTN1" ] }
-
humanMandatoryInfo
The
humanMandatoryInfo
component indicates a map that contains the list of tasks that are used by the activity and the corresponding human mandatory status. You can mark a task as Human Mandatory on the Task Classification page of IBM Task Mining. This indicates that the task requires a human input and hence, it cannot be automated. If a task is marked as Human Mandatory in the application, then it is marked as true in thehumanMandatoryInfo
JSON object. The generator can use this object to produce appropriate actions within the generated bot.Example 6: You can define the
humanMandatoryInfo
component as follows:"humanMandatoryInfo": [ { "taskName": "BTN1", "humanMandatory": false }, { "taskName": "BTN3", "humanMandatory": false }
Snippets
The snippets
JSON object holds the snippets for each of the tasks that are associated with the selected activity that is retrieved from IBM Task Mining. The generator script uses this object to build the RPA bot with the respective
snippet script for each task.
Example 7: The contents of a snippets
JSON object are as follows:
{
"preExecutionSnippet": "<pre-execution script>",
"postExecutionSnippet": "<post-execution script>",
"activity": "Calculator Operations",
"tasks": [
{
"taskName": "BTN1",
"snippets": [
{
"snippetName": "Button One",
"snippet": "<button one code>"
}
]
},
{
"taskName": "BTN3",
"snippets": [
{
"snippetName": "Button Three",
"snippet": "<button three code>"
}
]
},
{
"taskName": "BTN6",
"snippets": [
{
"snippetName": "Button Six",
"snippet": "<button six code>"
}
]
},
{
"taskName": "BTNPLUS",
"snippets": [
{
"snippetName": "Button Plus",
"snippet": "<button plus code>"
}
]
},
{
"taskName": "BTNMINUS",
"snippets": [
{
"snippetName": "Button Minus",
"snippet": "<button minus code>"
}
]
}
]
}
Table 2 lists the contents of the snippets
JSON object.
Table 2. Contents in the snippets
JSON object
Script | Description |
---|---|
preExecutionSnippet |
This script usually contains the boilerplate code that is required for the automation provider to run a script. This script contains the definitions of namespaces and import of libraries. |
postExecutionSnippet |
You can use this script to define the closing tags or actions necessary for the automation provider to successfully end an execution. |
activity |
Indicates the name of the activity that is automated. |
tasks |
This script contains the list of task names and the corresponding snippet details that include the snippet name, snippet description, and the script snippet. However, the generator does not use the name and the description of the snippet. |
contextualData
The rule expression in a transition from one task to another depends on the evaluation of expressions that contain the variables. In IBM Task Mining, every such variable is considered as a contextual data item. You can define the contextual data on the Task Classification page of IBM Task Mining. In the pluggable RPA bot generator script, you must ensure that the contextual data elements are declared as global variables so that the automation provider successfully runs these expressions.
This JSON object holds all the necessary information that is associated with contextual data. It also contains some additional variables that are not created by a user but by the system based on the CSV data. Table 3 lists some of the additional variables that are identified in the contextualData JSON object.
Table 3. Additional variables in the contextualData JSON object
Variable | Data type |
---|---|
PROCESSID | string |
ACTIVITY | string |
START-TIME | string |
END-TIME | string |
RESOURCE | string |
BUSINESSACTIVITY | string |
CASEPRODUCTIVE | integer |
CASEIDLE | integer |
APPLICATION | string |
These additional variables are added to the JSON object as part of the rule expressions in the BPMN, and thus in the generated bots.
You can exclude such resource variables from being updated as part of the BPMN. To do so, you can use the Edit Rule Configurations feature in the BPMN tab of the selected process in IBM Process Mining. For more information on BPMN tab, see Business Process Modeling Notation.
After excluding the system resources, use the Discover decision rules feature in the BPMN tab so that the BPMN reflects the latest changes. This process also removes such variables from BPMN, and from the decision rules in the generated bot.
Example 8: The contents of a contextualData
JSON object are as follows:
[
{
"name": "PRODUCT_NAME",
"rpaVariableName": "productName",
"rpaVariableType": "string",
"id": "Win32[@ClassName=RichEdit20WPT][@Type=edit][@Name=PName]",
"application": "saplogon",
"pageTitle": "Purchase Order Creation",
"fullUrl": ""
},
{
"name": "amount",
"rpaVariableName": "amount",
"rpaVariableType": "numeric",
"id": "Win32[@ClassName=AfxWndA][@Type=pane][@Name=amount]",
"application": "saplogon",
"pageTitle": "Purchase Order Creation",
"fullUrl": ""
},
{
"name": "BUSINESSACTIVITY",
"rpaVariableName": "businessactivity",
"rpaVariableType": "string",
"id": "attr-custom",
"application": "",
"pageTitle": "",
"fullUrl": ""
},
{
"name": "CASEPRODUCTIVE",
"rpaVariableName": "caseproductive",
"rpaVariableType": "integer",
"id": "attr-custom",
"application": "",
"pageTitle": "",
"fullUrl": ""
}
]
Each entry in the JSON represents a contextual data item and these items are represented as a global variable in the generated bot script.
Table 4 lists the contents of the contextualData
JSON object.
Table 4. Contents of the contextualData
JSON object
Data | Description |
---|---|
name |
Indicates the actual name of the contextual data item in IBM Task Mining. |
rpaVariableName |
Indicates the name of the variable in the generated bot script, which is a camel case representation of the contextual data name, removing spaces and special characters. |
rpaVariableType |
Indicates the data type of the contextual data. The generator script uses this contextual data item to map the variable type in the bot script. |
id |
Indicates the identifier of the contextual data in the application where the task was performed. |
application |
Indicates the name of the application where the task was performed |
pageTitle |
Indicates the page title of the page in which the task was performed. |
fullUrl |
Indicates the full URL of the application if it is a web-based application. |
Functioning of the pluggable RPA Bot generator script
In IBM Process Mining, to create an RPA bot, you need to select the candidate for automation and select the custom vendor for which you need to generate the RPA bot. You then click the Generate Bot for custom vendor button to initiate the bot generation process.
As soon as the bot generation process is initiated, the application fetches the generator script that is created for the vendor and the snippets of the selected activity from IBM Task Mining. It then loads all the necessary information about the activity such as the BPMN Data model, the rule expressions, the contextual data information, task aliases, and so on to the script. IBM Process Mining then runs the generator inside a JavaScript sandbox and generates a bot based on the supplied logic obtaining task and snippet information from the loaded data. The outcome of the execution is then converted into a file and downloaded.
The execution flow of the script is as follows:
-
The script builds a bot by traversing the JSON objects that are passed to it.
-
If pre-execution scripts are available for the selected candidate, it adds the contents to the resulting bot file.
-
Initializes a State Machine and sets the
startNode
as the initial State of the state machine. -
Processes the
startNode
. In this step, a State is added for this node within the state machine with a unique reference Id, so that you can refer the state from other nodes, and add the code snippet of this task to the Bot. If the script includes rule-based transitions, it generates and appends the Transition Conditions for each such transition. -
Iteratively process each node that is connected to the
startNode
, either direct transition or rule-based transition. -
Continue with Step 4 for each node in the chain till a node that is listed as an
endNode
is reached. This applies to all the flows from start to end. -
Add the contextual data variables as Global variables in the script.
-
Append the post-execution script to the bot.