Skip to main content
Solved

How to reference multiple variables in javascript to get a output

  • August 28, 2024
  • 5 replies
  • 219 views

Forum|alt.badge.img+6

Hi Devs,

 

Im trying to reference variable inside a javascript function to get a expected output in AA? how can i achive that?. I can able to reference one variable but for multiple variables i got stuck.

 

Adding my below JS script:

 

function addDaysToTimestamp(timestamp, daysToAdd) { // Convert the timestamp to milliseconds and create a Date object let date = new Date(timestamp * 1000); // Add the specified number of days date.setDate(date.getDate() + daysToAdd); // Convert the new date back to Unix timestamp (in seconds) return Math.floor(date.getTime() / 1000); }

Best answer by Stefano 5934

I just got time to test the bot and realized it wasn’t working correctly, here’s a corrected version:

I also revised the JavaScript code:

function concatenate(arguments)
{
  var name = arguments[0];
  var age = arguments[1];
  var dob = 2024 - age;

  return "" +
    name + " is " + age + " years old" +
    ", he was born in " + dob; 
}

You can find the source code of the bot here: 
A360-JavaScript_multiple_parametes.json  - GitHub Gist
You can use this extension to import the source code to a task bot: 
Bot Assistant - Chrome Web Store (google.com)

View original
Did this topic help answer your question?

5 replies

Forum|alt.badge.img+5
  • Navigator | Tier 3
  • 36 replies
  • August 28, 2024

You can create a list variable, subtype any, and add on it all the arguments that you'd like to pass to the javascript function.

JavaScript will interpret the list variable as an array, after that you can retrieve the values by their index.

Run JavaScript action - Automation Anywhere Documentation

JavaScript Arrays - W3Schools


Forum|alt.badge.img+6
  • Author
  • Navigator | Tier 3
  • 11 replies
  • August 28, 2024

Can u show me a example in the retrieve part? 

 


Forum|alt.badge.img+5
  • Navigator | Tier 3
  • 36 replies
  • August 28, 2024

Here's an example: 

function concatenate(arguments)
{
    var name = arguments[0];
    var age = arguments[1];
    return name + " is " + age + " years old";
}

 


Forum|alt.badge.img+5
  • Navigator | Tier 3
  • 36 replies
  • Answer
  • August 29, 2024

I just got time to test the bot and realized it wasn’t working correctly, here’s a corrected version:

I also revised the JavaScript code:

function concatenate(arguments)
{
  var name = arguments[0];
  var age = arguments[1];
  var dob = 2024 - age;

  return "" +
    name + " is " + age + " years old" +
    ", he was born in " + dob; 
}

You can find the source code of the bot here: 
A360-JavaScript_multiple_parametes.json  - GitHub Gist
You can use this extension to import the source code to a task bot: 
Bot Assistant - Chrome Web Store (google.com)


Forum|alt.badge.img+4
  • Navigator | Tier 3
  • 20 replies
  • August 29, 2024

Hi - Please check the below screenshots.

Thanks

Aravindh S

aravindhkumar002@gmail.com


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings