Forum Discussion

sameerjade's avatar
sameerjade
Frequent Contributor
9 years ago

Not able to have 2 scripts reference to each other, only allows one way referencing

Hello,

 

I have two scripts (Script1, Script2). Both contains various functions. I want to call a particular function from Script1 in Script2 and vice-versa. TestComplete does not allow this and gives an error: "The units Script1 and Script2 refer to each other. Cross references are not allowed in JScript units". Is this a known limitation in TestComplete? Is there a workaround to achieve what I am trying to do?

Note: To refer to script2 in script1, I add //USEUNIT Script2 at the top of Script1.

 

Thank you!

 

Sameer

6 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Check out https://support.smartbear.com/testcomplete/docs/scripting/specifics/jscript.html#no-circular-references-allowed-between-units.  Quote:

    "In TestComplete script units can refer to each other, so you can call routines and variables defined in other units. But JScript, C#Script and C++Script do not support circular references between units."

     

    What you described in your OP is exactly that... a circular reference.  This is not allowed in JScript.  If you are using TestComplete 12, you can easily convert your project to JavaScript which does not have that limitation.

     

    If you cannot convert, the best workaround is to move any common functions that both script files need into a common library, a Script3 if you would.  Then call the functions you need in Script1 and Script2.  This eliminates the circular reference.

    • sameerjade's avatar
      sameerjade
      Frequent Contributor

      Thank you Robert for your reply. That is quite helpful information. I did not know the difference between JScript and Java Script files earlier; after reading your reply I just started looking into it now. In fact, I earlier thought that I was working with Java Script files.

       

      I used the workaround that you mentioned that it is working for me.

       

      -Sameer

  • NisHera's avatar
    NisHera
    Valued Contributor

    Do you have circular reference in units...?

    in J script, circular reference are not allowed.

     

    I mean Unit 2 referring Unit 1 and .......Unit 1 referring Unit 2 ...etc.

    could be Unit 1 referring Unit 2 .....Unit (N-1) referring Unit N and Unit N referring Unit 1

     

     

    • sameerjade's avatar
      sameerjade
      Frequent Contributor

      Thank you, NisHera for your reply. Yes, I am doing circular referencing in my case. I was able to make it work by moving the functions that I wanted to call from one script to a new script thus avoiding the circular referencing.

       

      -Sameer

    • sameerjade's avatar
      sameerjade
      Frequent Contributor

      Thank you Shankar for your reply. Yes, I am calling the functions the same way you mentioned but seems like circular referencing is not allowed in JScript files (.sj).

       

      //USEUNIT Unit2 at the top of Unit1

       

      Then, in Unit1:

      Unit2.MyFunction();

       

      -Sameer