Unit 5 - Notes
INT346
Unit 5: Extending Automation 360 Capabilities with External Scripts
1. Introduction to External Scripts
1.1 Overview of External Scripting
While Automation 360 (formerly Automation Anywhere A2019) provides a robust set of drag-and-drop actions for low-code development, there are scenarios where native actions are insufficient for complex logic, specialized data processing, or legacy system interactions. External scripting acts as a bridge between low-code RPA and "pro-code" development.
Key Benefits:
- Extensibility: Allows developers to implement features not currently available in the native command library.
- Reusability: Existing code libraries and scripts used by IT teams can be integrated into RPA workflows without rewriting logic.
- Performance: Certain complex mathematical calculations or massive string manipulations execute faster in compiled code or optimized script interpreters than through UI-based loop actions.
1.2 Supported Script Types in Automation 360
Automation 360 offers dedicated packages to interface with various programming languages.
| Script Type | Primary Use Case | Automation 360 Package |
|---|---|---|
| Python | Data analysis (Pandas, NumPy), Machine Learning models, complex API handling, JSON parsing. | Python Script |
| VBScript | Windows OS automation, Excel macros, Active Directory management, legacy Microsoft application automation. | VBScript |
| JavaScript | Web-based automation, executing logic within a browser context, JSON manipulation. | Browser: Run JavaScript / JavaScript |
| DLL (C#/.NET) | High-performance system tasks, cryptography, utilizing .NET framework capabilities. | DLL |
1.3 Use Cases for External Scripts
- Complex Data Transformation: Using Python to merge, pivot, and clean large datasets using the Pandas library before the bot enters the data into an ERP system.
- Excel Macro Execution: Using VBScript to trigger complex formatting macros in Excel that are difficult to replicate using the native "Excel Advanced" package.
- Custom Cryptography: implementing specific encryption/decryption algorithms (like AES-256 with custom salts) using a C# DLL.
- Regular Expressions (Regex): While A360 has some Regex support, Python or JavaScript can handle complex multi-line pattern matching and extraction more efficiently.
2. Integrating External Scripts with Bots
Integration involves a standard lifecycle: Open/Load -> Execute -> Close.
2.1 Creating Bots with External Scripts
The general workflow for adding a script to a bot is as follows:
- Open/Load Action:
- Use the
Openaction specific to the language (e.g.,Python Script: Open). - Import Methods:
- Manual Input: Copy-paste code directly into the bot editor.
- Import File: Point to a
.py,.vbs, or.jsfile stored locally or in the Control Room repository.
- Use the
- Execute Action:
- Use the
Execute FunctionorRun Scriptaction. - Specify the name of the function to be called (for Python/DLL) or simply run the script (for sequential VBScript).
- Use the
- Close Action:
- Crucial for memory management. Use
Python Script: Closeor equivalent to terminate the session and free up the bot runner's resources.
- Crucial for memory management. Use
2.2 Passing Data Between Bots and Scripts
Data exchange is the most critical aspect of integration. Automation 360 variables must be mapped to script arguments.
Bot to Script (Input)
- Arguments List: In the
Execute Functionaction, developers can pass a list of arguments. - Data Type Compatibility:
- A360 String Python String.
- A360 Number Python Float/Integer.
- A360 List Python List.
- A360 Dictionary Python Dictionary.
- Best Practice: Ensure the script function definition matches the number and order of arguments passed by the bot.
Script to Bot (Output)
- Return Values: Scripts should return a value (usually a string or a structured object).
- Variable Assignment: The output of the
Execute Functionaction must be assigned to an Automation 360 variable (e.g.,sOutput). - Complex Data Return: If a script needs to return multiple values, it is best practice to return a JSON String. The bot can then parse this JSON string into a Dictionary variable.
2.3 Error Handling in Script-Based Bots
Script execution introduces a new layer of potential failure. Error handling must be implemented on two levels:
Level 1: Inside the Script (Internal Handling)
- The script should contain its own
Try-Catch(orTry-Exceptin Python) blocks. - If the script fails, it should catch the error and return a specific string (e.g.,
"ERROR: File not found") rather than crashing the interpreter.
Level 2: Inside the Bot (External Handling)
- Wrap the script execution actions in an Automation 360
Try-Catchblock. - Timeout Handling: Set a timeout in the script execution action. If the script hangs (infinite loop), the bot should terminate the action and move to the Catch block.
3. Best Practices for External Script Usage
3.1 Writing Efficient and Maintainable Scripts
- Modularity: Keep scripts small and focused on a single task. Avoid writing "monolithic" scripts that do everything.
- Stateless Execution: Ideally, scripts should be stateless. They accept input, process it, and return output without relying on global variables preserved between different function calls.
- Dependency Management:
- For Python, ensure all required libraries (e.g.,
pandas,requests) are installed on the Bot Runner machine. - Use
pip freezeto document dependencies.
- For Python, ensure all required libraries (e.g.,
- Comments and Documentation: Since RPA developers might not be expert coders, liberally comment on the external code to explain logic.
3.2 Security Considerations
- Credential Protection:
- NEVER hardcode credentials (passwords, API keys) inside the script file.
- ALWAYS retrieve credentials from the Automation 360 Credential Vault and pass them into the script as arguments at runtime.
- Input Validation: Sanitize inputs within the script to prevent injection attacks (e.g., SQL injection if the script connects to a DB, or Command Injection).
- Source Control: Store script files in the Control Room repository or an external Git repository to track changes and prevent unauthorized tampering.
3.3 Execution Policies
- Ensure the Bot Runner machine has the necessary permissions to execute scripts (e.g., PowerShell execution policies, Antivirus whitelisting for Python executables).
4. Examples of Advanced Script Integrations
Example A: Python for Advanced String Parsing
Scenario: A bot receives a raw address string "123 Maple St, Apt 4B, Springfield, IL, 62704" and needs to extract the Zip Code using Regex.
1. Python Script (extract_zip.py):
import re
def get_zip_code(address_string):
try:
# Regex to find 5 digit number at the end of string
match = re.search(r'\b\d{5}\b', address_string)
if match:
return match.group(0)
else:
return "NOT_FOUND"
except Exception as e:
return f"ERROR: {str(e)}"
2. A360 Implementation:
- Python Script: Open Import
extract_zip.py. - Python Script: Execute Function Function name:
get_zip_code. Argument:. Output to:. - If
== "NOT_FOUND", send an email to exception handler. - Python Script: Close.
Example B: VBScript for Excel Formatting
Scenario: An Excel report needs specific headers turned bold and yellow, which is tedious to do cell-by-cell in A360.
1. VBScript (format_excel.vbs):
Function FormatHeader(filePath, sheetName)
Dim objExcel, objWorkbook, objSheet
Set objExcel = CreateObject("Excel.Application")
' Open workbook invisibly
objExcel.Visible = False
Set objWorkbook = objExcel.Workbooks.Open(filePath)
Set objSheet = objWorkbook.Sheets(sheetName)
' Format Row 1
With objSheet.Rows(1)
.Font.Bold = True
.Interior.ColorIndex = 6 ' Yellow
End With
' Save and Close
objWorkbook.Save
objWorkbook.Close
objExcel.Quit
FormatHeader = "SUCCESS"
End Function
2. A360 Implementation:
- VBScript: Open Import
format_excel.vbs. - VBScript: Run Function Arguments:
[C:\Temp\Report.xlsx, Sheet1]. - VBScript: Close.
Example C: Passing Complex Data via JSON
Scenario: Python processes a dataset and needs to return the Total, Average, and Count to the bot.
Python Return:
import json
def calculate_metrics(data_list):
# ... logic ...
results = {
"total": 5000,
"average": 50,
"count": 100
}
return json.dumps(results) # Returns string: '{"total": 5000, "average": 50...}'
A360 Implementation:
- Bot receives the JSON string.
- Use JSON: Parse action (or Dictionary package) to convert the string into a Dictionary variable.
- Access values via keys (e.g.,
).