Showing results for 
Search instead for 
Did you mean: 

Accessing global variable values

Occasional Contributor

Accessing global variable values

Hi All,

Is there a way to access the values of the global variable in my case an array which gets value stored during the run time . 

To be specific consider there are 2 scripts unit1 and unit2 in unit1 I have declared an array say company(5) during run time the company array gets it value from a procedure in unit1 script. Can I access these values in procedures of script unit2 


Community Hero

RE: Accessing global variable values

Depending upon your script language the actual command may differ.  but, for JScript, you can use

at the beginning of your unit 2.  You can then call the variable as

Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Valued Contributor

RE: Accessing global variable values

The short answer is yes.

The complicated answer is that you may not have a circular reference.

That is UNIT2 cannot reference UNIT1 if UNIT1 already references UNIT2.

If you need to access the same variables from each script consider adding a third unit.

You'll want to use the USEUNIT statement in the beggining of your script to link scripts:

Then declare the global variable outside a function.

JScript Ex:



function main(){





function main2(){




company = new Array(5);


''-Praise the sun and Give Kudos.''
Regular Contributor

RE: Accessing global variable values

You could also try using the project and project suite variables. The variables and data will persist between test runs but you can always write a helper function to delete them when you are done. I use the project suite variables in my test runs for sharing data between scripts and it works great. In some cases I want the variables to persist between test runs and  in some I only need them to be temporary. For the latter case I have a script that deletes them at the end of a test run.

New Here?
Join us and watch the welcome video:
Top Kudoed Authors