Passing a Variable to .Js File

Hello!

I am using a .Js file in my project. It is working fine with me. But there is a bit of a change in the scenario, now I want to pass a variable to the .js file.

So I want to know, is it possible to pass a variable to a .js file? If yes! Can you please guide me?

Thanks in advance!

Best Regards

Declare a variable outside .js file with “assign value to variable”
Check “is global”
Use variable inside your code, without declaring it, you just have to use it

1 Like

@Muhammad_Hayyan As mentioned by @daniele_arcangeli Create a variable using ‘Assign value to variable’ and make it global. You can now use the variable in js file.

You can also find the recipes for the same. Please use below link or search for “How to work with javascript and Python” in recipes.

2 Likes

Hi!

I have tried the method you have mentioned @daniele_arcangeli @Kudlappa_Gouder. But it gives me error. Although I have made the variable global as well.

parameters for the Execute .JS file

Error

I forgot to share the .js code.

Here it is
image

Hello!

If you make input parametr empthy in execute js activity,
will it work?
(try to remove Client_Data in Input parametr option)

You just use your variable in js code

Best Regards

Hi @Muhammad_Hayyan, We would like to follow up if the solutions presented above.

Hi @Mabwa_Neek

As mentioned by @daniele_arcangeli @Kudlappa_Gouder. We have to make a variable, which want to pass in .JS file, as Global. Other than that we have to setup the methods in .JS file correctly for accessing the variable that is declared by BOT.

Following steps will work for anyone who wants to pass variable to .JS file.

Step One

Step Two

Step Three (Most importantly the syntax should remains the same)
image

Best Regards,
Muhammad Hayyan Khan

Thanks for sharing this feedback @Mikhail, @daniele_arcangeli, @Muhammad_Hayyan; this is very helpful to anyone who would like to learn how to pass a variable to a .JS file.

1 Like