Forum Discussion

chitra_c's avatar
chitra_c
New Contributor
11 years ago
Solved

How to pass variable with value from one script unit to another script unit within a Project

Hi,



I am trying to pass variable from one script to another script within a Project.



I have added a Department in Add_Department Script Unit. The added value stored in a variable. In Edit_Department Script unit we need that added Department value.



Seems like after running Add_Department script, if we pass the added department value in Edit Department it is retriving the passed value.



Anyone please help on this.





Regards

Chitra.

3 Replies

  • chitra_c's avatar
    chitra_c
    New Contributor
    Hi,



    Thanks for the reply. We followed the same with the link you have given. But it is not working.



    without running the whole Add_Department function, how can we call the variable and the stored value directly to Edit_Department. script Unit.



    Regards

    Chitra.C
  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    You must declare the variable outside the function for it to be a "global" variable, and also have the USEUNIT <scriptnamewithglobalvariable> added to scripts that need to acccess the global variable. Additionally you can use project variables.



    JScript Example:



    UNIT1:



    //USEUNIT UNIT2

    function main(){

    wshell.popup(myGlobalVariable);

    myGlobalVariable = 'test2';

    secondary();

    wshell.popup(myGlobalVariable);

    }





    UNIT2:



    wshell = new ActiveXObject('WScript.Shell');

    myGlobalVariable = 'test1';



    function secondary(){

    wshell.popup(myGlobalVariable);

    myGlobalVariable = 'test3';

    }