BACK

QuickTip: Building with Embedded Python

In this session, we’ll look at how to embed custom Python in a bot to enhance our ability to quickly and easy extract data.

Video Recap:

  1. Determine an Order of Operations
    1. When mentally thinking through how to solve problems, determine an order of operations for how you’ll proceed. As a good practice:
      1. Try to solve problems using packages alone. Most of the time this can get you the data/solution you need.
      2. When packages leave you short, understand your options…you could use embedded Python, embedded JavaScript, embedded VBScript, write a DLL and use the DLL package, or consider writing your own package (Java).
  2. Python Script: Open Action
    1. 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.
    2. 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.
  3. Call and Close the Script
    1. 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.
      1. 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.
      2. 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.
    2. Once all Python execution is complete, don’t forget to use the Close script action to end your Python script session.

Bonus Tip

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, your’re not limited to passing in a single parameter, or even a singe datatype.

Reference

If you want to build along with the video above, check out the GitHub project for the Python script used in the video.