2 Replies Latest reply: Jan 31, 2012 8:30 AM by Robert Svebeck RSS

    Help with GetAllVariables(callbackFn(object[]))

    Robert Svebeck

      Hi


      How can I write if I want the GetAllVariables(callbackFn(object[])) function to retrieve the value in a variable called "vGetColor1"?


      I have tried all sorts of things but I can not get anything to work.


      The example in the API is like this:


      Init = function() {
      var mydoc = Qv.GetCurrentDocument();
      mydoc.GetAllVariables(function(vars) {
      for (var i = 0; i < vars.length; i++) {
      var obj = vars[i];
      var name = obj.name;
      var value = obj.value;
      }
      });
      }


      This works good, and will loop through all variables in my document. I have tried to write an "IF (name = "vGetColor" ...) in there, but this value seems to exist only inside the function and I can't get it stored into a global JScript variable for some strange reason...


      What I'm looking for is a function something like this:


      function GetValueFromVariable(VariableName).
      {
      var mydoc = Qv.GetCurrentDocument();
      return mydoc.GetAllVariables(function(vars) {
      for (var i = 0; i < vars.length; i++) {
      var obj = vars[i];
      var name = obj.name;
      var value = obj.value;
      if (name==VariableName) return value;
      }
      };


      However, this does not work. All I get back from my function is "Undefined"....


      Please help me...


      Regards Robert