Variable Type Conversion In Automation Anywhere

Introduction

This article describes, how we can convert variable type in Automation Anywhere using community edition.

About Variables

Variables are used to store any value for future need like any calculation or passing value from one location to another location. We can use value via variable in rest of code based on variable scope. Sometimes we need to convert data from one type to another type so in Automation Anywhere there are couples of type casting options in different data types like-

  • Boolean
    • toNumber: Converts the Boolean value to a numeric value (True to 1 and False to 0).
    • toString: Converts the Boolean value to a string value.
  • Number
    • toString: Converts the number value to a string value
  • String
    • toBoolean: Converts the string value to a Boolean value.
    • toNumber: Converts the string value to a number value.

If you are a beginner then need to check this article Getting Started Robotic Process Automation using Automation Anywhere to create environment of Automation Anywhere.

Create a New bot

After logging Automation anywhere account through cloud community edition link,

You will see a Dashboard as shown in below image and you can create a new bot through highlighted button ‘create a bot’-

Bot Configuration

After clicking on ‘create a bot’ button, you will get a popup window. It will ask some information about bot which you want to create like-

  • Name of bot
  • Description of bot
  • Folder location of bot

After clicking on choose option, a popup window will come where you can browse ‘CSharpCorner’ folder and click on choose to set a default location for your new bot.

We gave name as ‘TypeConversion’ to my new bot. After clicking on ‘create & edit’, Bot Editor will look like below where you need to create 3 variables –

  • Boolean
    Click on create variable button (+) on left pane, and select type as ‘Boolean’ with name ‘BoolVariable’ & Default value as False.

  • Number
    Click on create variable button (+) on left pane, and select type as ‘Number’ with name ‘NumberVariable’ & Default value as 0.

  • String
    Click on create variable button (+) on left pane, and select type as ‘String’ with name ‘StringVariable’ & Default value as ‘This is Default String’.

 We can check your left pane with these newly created variables.

Now we need to convert our variables to different data types so let’s start with ‘Boolean’ variable.

Boolean Type Conversion

toString

Converts the Boolean value to a string value, so we will convert ‘BoolVariable’ value into ‘StringVariable’ as ‘BoolVariable’ is having its default value ‘False’, so that we will drag and drop ‘To String’ from Action pane->Boolean into workspace and change properties of it like boolean variable as ‘BoolVariable’ & select string variable as ‘StringVariable’.

toNumber

Converts the Boolean value to a number value, so we will convert ‘BoolVariable’ value into ‘NumberVariable’ as ‘BoolVariable’ is having it’s default value ‘False’, so that we will drag and drop ‘To Number’ from Action pane->Boolean into workspace and change properties of it like boolean variable as ‘BoolVariable’ & select Number variable as ‘NumberVariable’.

We will save the workspace and there will be no error in both conversions but if we want to check the values then we need to drag and drop ‘Message box’ from Action pane-> Message box into workspace. We will change the title of message box and in the message, we have to add ‘StringVariable’ and ‘NumberVariable’ to print their values but here is a catch. We can’t print directly ‘NumberVariable’ via message box so we need to convert it through toString method like-

String Value: $StringVariable$

Number Value: $NumberVariable.Number:toString$

Where output will look like after running the bot.

Number Type Conversion

toString

Converts the Number value to a string value, so we will convert ‘NumberVariable’ value into ‘StringVariable’ as ‘NumberVariable’, so that we will drag and drop ‘To String’ from Action pane->Number into workspace and add value in properties like,

  • Enter number with decimal(if want)
  • Enter digits after decimal(precision)
  • Select string variable as ‘StringVariable’.

Again, we will save the workspace and there will be no error in both conversions but if we want to check the values then we need to drag and drop ‘Message box’ from Action pane-> Message box into workspace. We will change the title of message box and in the message, we have to add ‘StringVariable’ to print their values like-

String Value:$StringVariable$

Where output will be look like after running the bot.

String Type Conversion

toBoolean

Converts the string value to a Boolean value, so we need to assign a value that can easily convert into Boolean variable like ‘True’ or ‘False’ so that we will drag and drop ‘Assign’ from Action pane->String into workspace and change properties of it like type value as ‘True’ & select destination variable as ‘StringVariable’.

After that we will convert ‘StringVariable’ value into ‘BoolVariable’, so that we will drag and drop ‘To boolean’ from Action pane->String into workspace and change properties of it like string variable as ‘StringVariable’ & select boolean variable as ‘BoolVariable’.

toNumber

Converts the string value to a number value, so we need to assign a value that can easily convert into Number variable like any digit so that we will drag and drop ‘Assign’ from Action pane->String into workspace and change properties of it like type value as ‘12345’ & select destination variable as ‘StringVariable’.

After that we will convert ‘StringVariable’ value into ‘NumberVariable’, so that we will drag and drop ‘To Number’ from Action pane->String into workspace and change properties of it like string variable as ‘StringVariable’ & select Number variable as ‘NumberVariable’.

We will save the workspace and there will be no error in both conversions but if we want to check the values then we need to drag and drop ‘Message box’ from Action pane-> Message box into workspace. We will change the title of message box and in the message, we have to add ‘BoolVariable’ and ‘NumberVariable’ to print their values but here is a catch. We can’t print directly these variables via message box so we need to convert them through toString method like-

Bool Value: $BoolVariable.Boolean:toString$

Number Value: $NumberVariable.Number:toString$

Where output will look like after running the bot.

Conclusion

In this article, how we can convert variable type in environment of Automation Anywhere.


Similar Articles