BACK

How to run JavaScript in A2019

Pre-requisite: Basic knowledge of JavaScript

In this tutorial, we will look at three examples.

In the first example, we will look at multiplying two numbers. In the second example, we will look at string concatenation. In the third example, we will look at converting a string to title case, where every new word starts with an uppercase letter.

Example 1: Multiply Two Numbers

Procedure

  1. Open a new bot.
    1. From Automation Anywhere web interface, select Bots > My bots.
    2. Click Create TaskBot.
    3. Enter a bot name: Multiply Bot
    4. Accept the default folder location \Bots\. To change where your bot is stored, click Choose and follow the prompts.
    5. Click Create and Edit.
  2. Create the following two variables.
    • lInputValues – Type: List, SubType: String, Default Value (optional): Value at 0 = 10, Value at 1 = 15
    • sOutput – Type: String
  3. Double Click or Drag Javascript – Open
    1. JavaScript: Default.
    2. JavaScript – Manual Input.
    3. Enter this JavaScript code.

    4. Click Apply.
  4. Double Click or Drag JavaScript – Run
    1. JavaScript session: Default.
    2. Enter name of function to be executed (optional): multiply.
    3. Arguments to the function (optional): lInputValues.
    4. Assign the output to variable (optional): sOutput.
    5. Click Apply.
  5. Double Click or Drag Message Box.
    1. Enter the message to display. Type: Result: $sOutput$
  6. Double Click or Drag JavaScript – Close: JavaScript session: Default.
  7. Click on Apply, Save & Run.

Here is the output.

Example 2: Adding Salutation to a User the Entered Name

Procedure

  1. Create a new bot.
  2. From Automation Anywhere web interface, select Bots > My bots.
    1. Click Create TaskBot.
    2. Enter a bot name: Hello User
    3. Accept the default folder location \Bots\. To change where your bot is stored, click Choose and follow the prompts.
    4. Click Create and Edit.
  3. Create the following three variables.
    • sInputList – Type: List, SubType: String
    • sInputName – Type: String
    • sOutput – Type: String
  4. Double Click or Drag Prompt for Value and place it under the start bot flow.
    1. Prompt window caption: Type: Enter your name
    2. Prompt message: Type: Enter your name here
    3. Assign the value to a variable: Select: sInputName
  5. Double Click or Drag List → Add Item
    1. List variable: Select: sInputList
    2. Item to be added: Select: sInputName
    3. Add item: Select: To end of list
  6. Create a JavaScript in your local system and add this code to the file.

    Create a JavaScript file as follows: Open an editor. Enter the above code. Save as Salutation.js.
  7. Double Click or Drag JavaScript – Open
    1. JavaScript: Default.
    2. JavaScript – Import Existing File, Click Desktop file, Click Browser and locate the JavaScript file Salutation.js created above.
    3. Click Apply.
  8. Double Click or Drag Javascript – Run
    1. JavaScript session: Default.
    2. Enter name of function to be executed (optional): response
    3. Arguments to the function (optional) Parameters: sInputList
    4. Assign the output to variable (optional): sOutput
    5. Click Apply
  9. Double Click or Drag Message Box.
    1. Enter the message to display: Press F2 and select: $sOutput$
    2. Click Apply.
  10. Save & Run the Bot.

The input and output screenshots as a reference.

Input:

Output:

Example 3: Converting String Text to Title Case

Procedure

  1. Create a new bot.
  2. From Automation Anywhere web interface, select Bots > My bots.
    1. Click Create TaskBot.
    2. Enter a bot name: TitleCaseConverter
    3. Accept the default folder location \Bots\. To change where your bot is stored, click Choose and follow the prompts.
    4. Click Create and Edit.
  3. Create the following three variables.
    • sInputList – Type: List, SubType: String
    • sInputName – Type: String
    • sOutput – Type: String
  4. Double click or drag Prompt for Value.
    1. Prompt window caption: Enter a phrase
    2. Prompt message: Please enter the phrase to be converted to Title Case
    3. Assign the value to a variable: sInputName
  5. Double Click or Drag List → Add Item
    1. List variable: Select: sInputList
    2. Item to be added: Select: sInputName
    3. Add item: Select: To end of list
  6. Create a JavaScript in your local system and add this code to the file.

    Create a JavaScript file as follows: Open an editor. Enter the above code. Save as TitleCase.js.
  7. Double Click or Drag Javascript – Open
    1. JavaScript: Default.
    2. JavaScript – Import Existing File, Click Desktop file, Click Browser and locate the JavaScript file Salutation.js created above.
    3. Click Apply.
  8. Double Click or Drag Javascript – Run
    1. JavaScript session: Default.
    2. Enter name of function to be executed (optional): TitleCase
    3. Arguments to the function (optional): sInputList
    4. Assign the output to variable (optional): sOutput
    5. Click Apply.
  9. Double Click or Drag Message Box.
    1. Enter the message to display: Press F2 and select: $sOutput$
    2. Click Apply.
  10. Save & Run the Bot.

The input and output screenshots as a reference.

Input:

Output: