Forum Discussion

Preetha's avatar
Preetha
Occasional Contributor
6 years ago

how can we pass an object defined in one unit to another

how can we pass an object defined in one unit to another in java csript.

 

I have imported the unitA(where the object is declared) in Unit B where i need to use the object.

  • Hi,

     

    You need to return required value from the function like it was advised by Vinicius.

    Like this:

    //OpenFB unit

    function openurl()
    {
      var browser;
      var page;

      Browsers.Item(btChrome).Run("https://www.facebook.com/");
      browser = Sys.browser();
      page = browser.Page("*facebook.com*");
     // page.NativeWebObject.Find("name","websubmit","BUTTON").Click();  this code is working when executing from unit OpenFB

     

      return page; // <== added line
    }

     

    //Unit B

     

    //USEUNIT OpenFB
    function mandatory_check()
    {

        var page;

     

        page = openurl();   // <== OpenFB. is not required because of //USEUNIT OpenFB directive
        page.NativeWebObject.Find("name", "websubmit", "BUTTON").Click();
     }

     

  • Vinicius's avatar
    Vinicius
    Occasional Contributor

    Maybe you can go with something like:

     

    Unit 1:

    function returnObj(){

    return Sys.Process('app').Caption('text');

    }

     

    And inside the unit 2 you can call the function.

     

     

    • Preetha's avatar
      Preetha
      Occasional Contributor

      Thanks

      I am able to call the function of another unit but not able to use  the variable/object declared in another unit.

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    Can you post here your code so that others can see exact implementation and be able to share their ideas?

     

    • Preetha's avatar
      Preetha
      Occasional Contributor

      Hi Alex

      My code is as below

       

      //OpenFB unit

      function openurl()
      {
        var browser;
        var page;

        Browsers.Item(btChrome).Run("https://www.facebook.com/");
        browser = Sys.browser();
        page = browser.Page("*facebook.com*");
       // page.NativeWebObject.Find("name","websubmit","BUTTON").Click();  this code is working when executing from unit OpenFB
      }

       

      //Unit B

       

      //USEUNIT OpenFB
      function mandatory_check()
      {
          OpenFB.openurl();   //  --this line is working it is calling the above function
         OpenFB.page.NativeWebObject.Find("name","websubmit","BUTTON").Click();  // giving error says "Cannot read property 'NativeWebObject' of undefined  "
       }

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        You need to return required value from the function like it was advised by Vinicius.

        Like this:

        //OpenFB unit

        function openurl()
        {
          var browser;
          var page;

          Browsers.Item(btChrome).Run("https://www.facebook.com/");
          browser = Sys.browser();
          page = browser.Page("*facebook.com*");
         // page.NativeWebObject.Find("name","websubmit","BUTTON").Click();  this code is working when executing from unit OpenFB

         

          return page; // <== added line
        }

         

        //Unit B

         

        //USEUNIT OpenFB
        function mandatory_check()
        {

            var page;

         

            page = openurl();   // <== OpenFB. is not required because of //USEUNIT OpenFB directive
            page.NativeWebObject.Find("name", "websubmit", "BUTTON").Click();
         }