1 Reply Latest reply: Jul 17, 2014 10:15 AM by Ralf Becher RSS

    Reading Variable Definition in a Document

      Hello,

       

      our goal is to read all the variable defintions in a document. The Problem ist that only 2 variables are displayed in the extension.

      If I have selected 3 individual variable definitions to display them, I get an error code 2. In the loop as shown in the sample below it display just 2 rows.

      Can anyone help me to get all variable definitions in a exportable format!? It's very important for me and I am not find any solution.

       

      Thanks in advance!

       

      Best Rgds

       

      Martin

       

      Thats the sample code:

       

       

      Qva.AddExtension('Konsolidierung', function(){


      var obj = this.Element;

            var doc = Qv.GetCurrentDocument();

            var varsRetrieved = false;

            doc.SetOnUpdateComplete(function(){

                 if(!varsRetrieved){

                      Qv.GetDocument("").GetAllVariables(function(variables){

                           for(var i = 0; i < variables.length; i++){

         
                  var a = variables[i].name + " = " + variables[i].value;        
                  obj.innerHTML=a;
           
         //var Konsolidierung = this.GetVariable();

         //obj.getElementById("ptest").innerHTML = variables[i].name + " = " + variables[i].value;
         //this.Element.appendChild(p);

          //alert(variables[i].name + " = " + variables[i].value);

                          

                      }});

                      varsRetrieved = true;
        


                 }

            });

        }, false);

        • Re: Reading Variable Definition in a Document
          Ralf Becher

          Hi Martin,

           

          this is what works for us:

          ---

          (function() {

              Qv.AddExtension('ReadVariables', function() {

                  console.log('ReadVariables eXtension loaded');

           

                  var height = this.GetHeight();

                  var width = this.GetWidth();

           

                  var container = $('<div />').css({

                      height: height,

                      width: width,

                      overflow: "auto"

                      }).appendTo($(this.Element).empty());

           

                  Qv.GetCurrentDocument().GetAllVariables(function(vars) {

                      $.each(vars, function(index, varObj) {

                          container.append($('<div>' + varObj.name + ' = ' + varObj.value + '</div>'));

                      });

                  });

              });   

          })();

          ---

          It's worth to mention that the callback function of GetAllVariables( ) runs asynchronous which gives a problem if you assign the values inside to an outer scope variable.


          - Ralf