Skip to main content
Solved

How to reference variable within Run Javascript with manual input

  • February 23, 2023
  • 7 replies
  • 1577 views

Forum|alt.badge.img+5

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

Best answer by Padmakumar

bradwyatt wrote:

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

View original
Did this topic help answer your question?

7 replies

Padmakumar
Forum|alt.badge.img+13
  • Navigator | Tier 3
  • 785 replies
  • February 23, 2023

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.


Forum|alt.badge.img+5
  • Author
  • Navigator | Tier 3
  • 10 replies
  • February 23, 2023

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


Forum|alt.badge.img+6
  • Navigator | Tier 3
  • 142 replies
  • February 23, 2023

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
Forum|alt.badge.img+13
  • Navigator | Tier 3
  • 785 replies
  • Answer
  • February 24, 2023
bradwyatt wrote:

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


Forum|alt.badge.img+2
  • Cadet | Tier 2
  • 7 replies
  • May 3, 2023

It worked thank you


Forum|alt.badge.img
  • Cadet | Tier 2
  • 1 reply
  • August 4, 2023
Lekharaj wrote:

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


Forum|alt.badge.img+3
  • Navigator | Tier 3
  • 15 replies
  • November 29, 2024

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

 


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