Skip to main content

Hi all,

I’m Darshan Hiranandani, trying to use the "Run Javascript" action in Automation Anywhere with manual input, but I need to reference an RPA variable within the JavaScript code.

For example, I have a variable $variableInRPA$ (which holds a value like 50), and I want to add 10 to it in the JavaScript code, then return the result. Here's what I’ve been attempting:

(function(){
    var variableInManualInput = $variableInRPA$;
    var result = variableInManualInput + 10;
    return result;
}());

Is there a way to pass the RPA variable into the JavaScript code correctly? I’m unsure how to reference it properly for this use case.

Has anyone encountered this before and figured out a solution? Any tips or suggestions would be greatly appreciated!

Thanks in advance!

Regards

Darshan Hiranandani

You cannot. One is a client side scripting language, one is a server side language. 

What you can do is to have your automation write dynamic JavaScript with the values of the variables. This can be done with the Log Text To File action (to write it to a file) or carefully concatenating a string variable with the JavaScript contents inside.


Check out the following thread: How to reference multiple variables in javascript to get a output | Community

The question in that thread asks about passing multiple variables to a JavaScript function, but you could apply the same logic to pass a single variable to your JavaScript code.


Reply