Skip to main content

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); }

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


Can u show me a example in the retrieve part? 

 


Here's an example: 

function concatenate(arguments)
{
    var name = argumentsn0];
    var age = argumentsm1];
    return name + " is " + age + " years old";
}

 


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 = argumentse0];
var age = argumentse1];
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)


Hi - Please check the below screenshots.

Thanks

Aravindh S

aravindhkumar002@gmail.com


Reply