In this session, we’ll look at how to embed custom Python in a bot to enhance our ability to quickly and easily extract data.
Determine an Order of Operations
When mentally thinking through how to solve problems, determine an order of operations for how you’ll proceed. As a good practice:
Try to solve problems using packages alone. Most of the time this can get you the data/solution you need.
Python Script: Open Action
Adding embedded Python to a bot starts with adding the Open Script action. Using this action, developers can choose to execute Python scripts located in their Control Room, on a desktop/share location, a location referenced by a variable, or by manually inputting the script directly into the Open Script action.
In the example, we used the manual input – which is totally fine to use – but consider storing such a script in the Control Room when the script may find reuse across other bots.
Call and Close the Script
Once the Open Script location/script has been established, use either the Execute Function or Execute Script action to run the code within your bot.
Execute Function allows developers to specify one (of possibly many) functions to call and specify any input to map to them – perfect for use cases where you need to run a script and pass in some values.
Execute Script takes in no input but will execute the script in its entirety – useful if your script doesn’t have a specific function that needs to be called so much as just the script being executed.
Once all Python execution is complete, don’t forget to use the Close script action to end your Python script session.
If you wrote a function but need to pass in more than one parameter you may have noticed that the package itself only allows for a single parameter to be passed in. Fear not! Consider passing in a dictionary from Automation Anywhere Enterprise A2019 and parsing that dictionary at the beginning of your Python script to establish all the input values needed. In this way, you’re not limited to passing in a single parameter, or even a single datatype.
If you want to build along with the video above, check out the GitHub project for the Python script used in the video.