Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

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.name + " = " + variables.value;        
            obj.innerHTML=a;
     
   //var Konsolidierung = this.GetVariable();

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

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

                    

                }});

                varsRetrieved = true;
  


           }

      });

  }, false);

1 Reply
rbecher
MVP
MVP

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

Astrato.io Head of R&D