How To Execute A JavaScript File In Automation Anywhere

Introduction

This article describes, how to execute a JavaScript file code like adding 2 values and showing them in Automation Anywhere using the community edition.

If you have a small piece of JavaScript code in a file to run it but don’t have knowledge of JavaScript, so no need to worry still you can execute that code. You just need to pass that JavaScript function name, input parameter (if any) and output parameter (if any) that’s it. So let’s begin this article.

JavaScript File with code

I have a JavaScript file(AddValues.js) with a function named ‘AddValues’ which is adding 2 values that are sent as input parameters and returns the addition of both values.

How to Execute a JavaScript file in Automation Anywhere

Now I need to create bot to execute this code a get sum of values. If you are a beginner then need to check this article Getting Started Robotic Process Automation using Automation Anywhere to create an environment of Automation Anywhere.

Create a New bot

After logging Automation anywhere account through cloud community edition link,

How to Execute a JavaScript file in Automation Anywhere

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

How to Execute a JavaScript file in Automation Anywhere

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

How to Execute a JavaScript file in Automation Anywhere

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.

How to Execute a JavaScript file in Automation Anywhere

After creating bot, we will create 1st variable of ‘list’ type and 2nd as string variable for output parameter.

Create Variable for Input and output Parameter

Let’s create a variable through left side variable pane and click on ‘+’ sign, and select ‘List’ type with ‘Number’ subtype after that fill the variable name as ‘InputParameters’ and click on create button.

How to Execute a JavaScript file in Automation Anywhere

And do the same for output parameter with name as ‘Output Parameter’ but with ‘String’ type

How to Execute a JavaScript file in Automation Anywhere

Assign values to Input parameters

Now Go to ‘Action’ pane on left side and find ‘Assign’ from ‘List’ section (List ->Assign). Drag & drop it on workspace and add 2 values of number type through ‘+’ button which you want to pass in JavaScript function as input parameter and i filled 100 and 200 values over here.

Next just select ‘InputParameters’ as destination variable to get number value.

How to Execute a JavaScript file in Automation Anywhere

Open JavaScript and Import existing file

Now Go to ‘Action’ pane on left side and find ‘JavaScript’ section. Drag & drop ‘Open’ into workspace. Follow the below steps

  • Select ‘Import existing file’ radio
  • Select ‘Desktop file’ tab
  • Browse JavaScript file from computer which we created earlier(AddValues.js) and having below function
function AddValues(value1, value2){
    var sum=value1 + value2;
    return sum;
}

How to Execute a JavaScript file in Automation Anywhere

Run JavaScript

Go to ‘Action’ pane on left side and find ‘JavaScript’ section. Drag & drop ‘Run Javascript’ into workspace. Enter name of JavaScript function named ‘Addvalues’ which is optional, Parameter as ‘InputParameters’ variable and output to variable as ‘OutputParameter’ variable.

How to Execute a JavaScript file in Automation Anywhere

Close JavaScript

Go to ‘Action’ pane on left side and find ‘JavaScript’ section. Drag & drop ‘Close’ into workspace to close JavaScript.

How to Execute a JavaScript file in Automation Anywhere

Message Box to show Output Variable

Go to ‘Action’ pane on left side and find ‘Message box’ section. Drag & drop ‘Message box’ into workspace to display output variable. You need to just add title name as ‘Show JavaScript Output’ and select ‘OutputParameter’ in message to display.

How to Execute a JavaScript file in Automation Anywhere

Where output will be look like after running the bot.

How to Execute a JavaScript file in Automation Anywhere

Conclusion

In this article, how you can execute a code that exists in JavaScript file in environment of Automation Anywhere.


Similar Articles