How to Use the Actions in the DLL Package

  • 16 April 2021
  • 0 replies
  • 659 views

Userlevel 6
Badge +9

In this exercise, we will learn how to use the actions in the DLL package. The DLL package uses a .dll file as reference and calls functions from the bot. The DLL package supports only DLLs written in C#.

To learn about the different actions in this package, let’s consider a use case to get the current price of Bitcoin in USD and EUR. For this exercise, we will use a DLL (BitcoinPrice.dll) that retrieves the current Bitcoin price through a REST API call and uses a dependent DLL RestSharp.dll to perform the REST calls.

Dependency for BitcoinPrice.dll: Restsharp DLL (Source: RestSharp) - This is a simple REST and HTTP API Client.

You can download the DLLs (BitcoinPrice.dll and RestSharp.dll along with the code to build BitcoinPrice.dll in Visual Studio) used in this exercise from Automation Anywhere GitHub Repo.

In this exercise, we will not focus on how to build this DLL, however, if you wish to build it yourself with Visual Studio, please use the project type Class Library (.Net framework) as shown below. In this exercise, we will use the 3 actions in the DLL package: Open, Run function, and Close.

As we are using 2 DLLs, ensure we have both the DLLs in the same Control Room folder. Step 1: Create a new bot and use Open action in the DLL package: This action opens the reference DLL file and establishes a connection to execute functions in the next step.

In the Session Name field, enter the name of the session. I will retain the value ‘Default’.

In the File path field, specify the location of the path where the DLL is stored. It can either be in your local system or you can add it to Control Room and specify the folder path in CR. We will upload the DLL file to the Control Room and specify the path. Step 2: Use the Run function in the DLL package. This action will execute the function within the .dll file. Specify the parameters to be passed to a function and store the output as a variable. You can get the details about the different data types supported in DLL functions here.

Enter the same DLL session name ‘Default’ as used in Step 1.

Add the following information in the corresponding fields: This information is taken from the file GetBitcoinPrice.cs which is part of the BitcoinPrice.DLL (it’s available to see in the Github repository).

Namespace: BitcoinPrice

Class Name: GetBitcoinPrice

Name of the function to be executed: GetPriceOfBitcoin

Kindly note, these fields are case-sensitive and will throw errors if the names are not correct.

Here is the mapping from the Class file to the fields in the DLL Run function action. We have to pass the Currency as a parameter to the DLL Fun function, enter the value “USD” as shown below, which will output the Bitcoin price in USD. Assign the output from the function (which is the price of the Bitcoin) to a string variable. Create a variable called sBitcoinPrice and assign the output to this variable.

The full DLL Run function will look as shown in the image here.

 

In this example, as the DLL BitcoinPrice.dll file uses .NET classes from the Restsharp DLL file, you must add the Restsharp DLL file as a manual dependency to the bot. You can do so by clicking on the 3 dots to the next of the button 'Debug' on the top right side of your bot editor.

If the manual dependency is not added, here is the error you will see when you execute the bot.

 

Step 3: Add a Message box to display the Bitcoin price. Use the message text as ‘Current Bitcoin price in USD is $$$sBitcoinPrice$’. Notice the additional 2 $ symbols as a prefix to the variable $sBitcoinPrice$, this is added to display one $ before the Bitcoin price and the other $ is an escape character to let one $ symbol be displayed. To summarize, $$ will display $ in the message box.

You will see the output as shown below.

 

Step 4: Use Close action in the DLL package: This action closes the current session. In the Session Name field, enter the same session name as used in the action Open (i.e., Default)

This concludes the exercise.

Just to let you know, there is also a 4th action in the DLL package Run function (Legacy) action which is not recommended to be used from the .16 release and hence I haven't covered the same in this exercise.

Packages Used: DLL

Message box

Conclusion: If you have existing DLLs which were built to be used with Automation Anywhere V11, the DLL package is a great way to use the existing DLLs in the Automation 360 platform and enjoy the new features provided by the platform.

Similar to how DLLs could be used to extend Automation Anywhere platform capabilities in V11, you can build packages to extend Automation 360 capabilities or even bring in your own custom functions. Here is a tutorial on how to build a package using Automation Anywhere SDK.


0 replies

Be the first to reply!

Reply