How to reference variable within Run Javascript with manual input
Hello,
I want to use the Run Javascript action with manual input, but I’d like to reference a variable from RPA in the code.
For example, let’s say I have $variableInRPA$ as a number (like 50) in RPA, and in the code I want to add 10, then return result. Like this:
(function(){ var variableInManualInput = $variableInRPA$; var result = variableInManualInput + 10; return result; }());
How do I do this?
Thanks
Page 1 / 1
Hi @bradwyatt ,
You can pass the parameter to a JavaScript using the Run: Javascript action by selecting it from the Parameters drop-down list.
In your case (as per the example given above) the parameter to pass will be $variableInRPA$ and you can mention something like addition inside the parenthesis of Function and later specify the same under Run: Javascript part as well.
You can remove the second line completely from your code.
@Padmakumar - Sorry for not being specific enough in my original question, but is it possible to do this for “Browser: Run Javascript”? What you have mentioned above looks to be from just “Run Javascript”.
You could write your script to file first, this would write with variable values and then use “import existing file” option inside Browser: Run Javascript
For complex objects you can write as JSON string then parse inside JavaScript.
@Padmakumar - Sorry for not being specific enough in my original question, but is it possible to do this for “Browser: Run Javascript”? What you have mentioned above looks to be from just “Run Javascript”.
If you haven’t watched it yet, please do watch the below QuickTip on the same.
Also, passing AA variable is not possible in manual script. However, you can use the Log to File action to write the JavaScript and variables to a .js file and then use the Browser: Run JavaScript action to execute this file.
It worked thank you
It worked thank you
Hello, how did you solve it? I have the same problem and I don't know how to execute it with a variable in AA
I know this topic is old, but I would like to park a comment on it. The documentation on running Javascript is woefully elementary and does not discuss much in terms of technical information.
Variable values to be passed as parameters are passed as a list. But do not append your first parameter value “To end of list”. Your first parameter value MUST be at index 0 of the list.
You can append additional values after this one has been established at 0.
Results returned from the function are returned as a string. Either your result has to respond to a .toString() function or you have to set it as a string yourself. The following two functions return the same result: a comma delimited string “1,2,3,4,5”.
function string_parse() { return /1,2,3,4,5]; } function string_parse() { return 1,2,3,4,5].toString(); }
There is no way to identify errors in your js code. You need to test that in some other js interpreter (I use JetBrains WebStorm.) It is simply going to return “bot error”.
Keep in mind that you can’t do everything you want in the JavaScript. A video example uses the Math library to calculate a Sin value. Works great. However, I cannot get anything to work using the RegExp library. Everything I try returns “bot error”.