Forum Discussion

royd's avatar
Regular Contributor
8 years ago

Global variable trouble!

Hello everyone


I am having serious trouble with Global vaiebles! In the past, I did use Global variable successfully. Only difference this time is, I have 3 Global variable coming from UnitA to UnitB and 3 Variables coming from UnitB to UnitC (one new from UnitB). I have wasted much time last week, can not figure out the problem!


I am using TestComplete 12 with JScript. Here is my setup:


UnitA(with UnitB reference)                    UnitB(with UnitC reference)                     UnitC


and . . .




var fName
var securityC
var getURL

function atHomePatient(){

  Browsers.Item("iexplore", "", Browsers.pX86).Run("https://<url>");

. . . 

//select department

//set admission date

//set patient name
Aliases.browser.pageHIS.aspNet.pName.SetText(patient.pName); //i.e: John Smith
fName = patient.pName.split(" ")[0];
Log.Message("Split first name is: " + fName);

//set DOB

. . .




function patientSignOn(){

Log.Message("Patient's Name is: " + fName);
Log.Message("Security code is: " + securityC);
Log.Message("Signup url is: " + getURL);

. . .


Here is the structure of my project:


All three reported 'undefined' in UnitB!


I would really appreciate any help!





  • That's to be expect... you are trying to use B unit code in unit A... which is not allowed because you're not allowed circular references...

    What this comes down to, honestly, is that you're going to need to re-engineer some stuff so that you keep your code modularized in specific units so you don't end up with circular references.  Unfortunately, that's you're only recourse here... in order to call the code you want to call, you need USEUNIT clauses... but you can't do that because doing so puts you in the situation of having circular references... the only solution is to re-engineer.

13 Replies

  • shankar_r's avatar
    Community Hero

    There are two ways,


    1) Using //USEUNIT in your UnitB and UnitC .

    2) Using your global variable prefixed with their unit name Unit.fName


    If you are not into any of these 2 ways then you will get undefined

    • royd's avatar
      Regular Contributor

      Hi Shankar


      Good to see you again.


      JScriptdoes does not allow the use of circular references see here


      Just tried your second suggestion and got the following error:


      Microsoft JScript runtime error.

      'AA_Create_Patient' is undefined.



      Any idea?





      • tristaanogre's avatar
        Esteemed Contributor

        royd, correct, it does not allow circular references, but you still need to have a //USEUNIT statement at the top of your unit to tell it to include variables and methods from another script unit.  Without that, you'll get exactly the result you got.  If you have B referencing A and then A referencing B again, that's not allowed.  But so long as it's just a single line, shouldn't be a problem.


        In other words, your UnitB should look like this:


        //USEUNIT AA_Create_Patient;
        function patientSignOn(){
        Log.Message("Patient's Name is: " + AA_Create_Patient.fName);
        Log.Message("Security code is: " + AA_Create_Patient.securityC);
        Log.Message("Signup url is: " + AA_Create_Patient.getURL);
        . . .