Question

How to reference variable within Run Javascript with manual input

  • 23 February 2023
  • 6 replies
  • 938 views

Badge +4

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


6 replies

Userlevel 7
Badge +13

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.

Badge +4

@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”.

Userlevel 3
Badge +6

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.

Userlevel 7
Badge +13

@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. 

Badge +2

It worked thank you

Badge

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

Reply