locked
Why do global variables not get updated when the variable is updated in a function RRS feed

  • Question

  • I have declared the variables globally and then populate the variables in the functions. The variable values are not retuened to the calling functions.

    Can somehelp help why this is happening?

    Thank you

    Darryl.


    var my_Portlet1;
    var my_Portlet2;
    var my_Portlet3;
    var my_Portlets2Show;
    var my_PortletPath1;
    var my_PortletPath2;
    var my_PortletPath3;

    // --------------------------------------------------------------------------------

    function loadA4GPortal() {
     try  { closeA4GPortal(); }
     catch(error) {  }
     if (vUser == null) {
      app.msgbox ("Invalid User","Debug vUser");
      vUser = "A4G_LOOK";
     }
     
     openA4GPortal();
     loadA4GOptions(vUser, my_Portlet1, my_Portlet2, my_Portlet3, my_Portlets2Show, my_PortletPath1, my_PortletPath2, my_PortletPath3);
     closeA4GPortal();
     
     if (my_Portlet1 != null) {
      app.MsgBox (my_Portlet1, "Info myPortlet1");
     }
     if (my_Portlet2 != null) {
      app.MsgBox (my_Portlet2, "Info myPortlet2");
     }
     if (my_Portlet3 != null) {
      app.MsgBox (my_Portlet3, "Info myPortlet3");
     }
     if (my_PortletPath1 != null) app.MsgBox (my_PortletPath1, "Info myPortletPath1");
     if (my_PortletPath2 != null) app.MsgBox (my_PortletPath2, "Info myPortletPath2");
     if (my_PortletPath3 != null) app.MsgBox (my_PortletPath3, "Info myPortletPath3");
     if (my_Portlets2Show != null) app.MsgBox (my_Portlets2Show, "Info myPortlets2Show");

    }

    function openA4GPortal(){
     var sConnectString = "Connection=a4gi501;Mode=ReadWrite|ShareDenyNone";
     app.DBConnect ("Connection2myAccount", nlDBServerDDM, sConnectString);
     varFile2Read = "A4G_LOOK/LSMYA01P";
     // openEmsRecordset("myAccount_RecordSet",varFile2Read, 1, 1, 2, 5);
     openEmsRecordset("myAccount_RecordSet",varFile2Read);
    }

    function closeA4GPortal() {
     Connection2myAccount.Close("myAccount_RecordSet");
     Connection2myAccount.Disconnect();
    }

    function openEmsRecordset(sRecordset, sSource){
     Connection2myAccount.Open (sRecordset, sSource);
    }

    function loadA4GOptions(vUser, my_Portlet1, my_Portlet2, my_Portlet3, my_Portlets2Show, my_PortletPath1, my_PortletPath2, my_PortletPath3){ 
     
     myAccount_RecordSet.Move(nlDBMoveFirst);
     // while (!LSMYA01P_RecordSet.EOF && record_found = "No"){   
     while (!myAccount_RecordSet.EOF ){   
     if (myAccount_RecordSet.Fields(0).Value != null)
     {
      my_userid = myAccount_RecordSet.Fields(0).Value;
      my_key   = trim(myAccount_RecordSet.Fields(1).Value);
      
      if (trim(my_userid) == trim(vUser) ) {
       // If (my_key == "KEY1" ) {
        my_Portlets2Show = 1 *  myAccount_RecordSet.Fields(5).Value;
        if (my_Portlets2Show != null) {
        // app.MsgBox (my_Portlets2Show, "Info myPortlets2Show");
        }
        my_Portlet1      = trim(myAccount_RecordSet.Fields(6).Value);
        if (my_Portlet1 != null) {
         app.MsgBox (my_Portlet1, "Info myPortlet1");
        }
        my_Portlet2      = trim(myAccount_RecordSet.Fields(7).Value);
        my_Portlet3      = trim(myAccount_RecordSet.Fields(8).Value);
        my_PortletPath1  = trim(myAccount_RecordSet.Fields(9).Value);
        my_PortletPath2  = trim(myAccount_RecordSet.Fields(10).Value);
        my_PortletPath3  = trim(myAccount_RecordSet.Fields(11).Value);
        record_found  = "Yes";
        return  (vUser, my_Portlet1, my_Portlet2, my_Portlet3, my_Portlets2Show, my_PortletPath1, my_PortletPath2, my_PortletPath3);

       // }
      }
      myAccount_RecordSet.Move(nlDBMoveNext);
     }
     }
    }

    Friday, November 20, 2009 7:17 PM

All replies

  • ...
    that's because you are modifying 'closures' and/or local function variables/arguments instead of global vars with the same name.
    Tuesday, November 24, 2009 7:57 PM