6 Replies Latest reply: Sep 6, 2016 10:23 AM by Erik Wetterberg RSS

    Listing all measures in an extension (Title, description, expression)

    Nathan S

      Hey There,

       

      I'm experimenting with creation of an extension.  The purpose of the extension is to list all measures in the app including 1) Title, 2) Description and 3) Expression.  The below code seems to work fine in doing (1) and (2), but I'm not sure how to find the expression value of each of the measure.  The reply doesn't seem to contain the expression value.

       

      In a separate issue, it doesn't seem possible to export data using the extension.  I get the error, "Export Failed.  There is no data to export.  Please make sure the data in your visualization is correct."  Does anyone know how to code the extension so that I can export the data to excel? 

       

      Any help would be greatly appreciated.

       

      define( ["qlik"],
      function (qlik) {
      
      
        return {
        snapshot: {
        canTakeSnapshot: true
        },
        paint: function ($element) {
        //add your rendering code here
                            
                              app = qlik.currApp(this);
        app.createGenericObject({
                              qMeasureListDef : {
                                                      qType: "measure", qData: { title: "/title", tags: "/tags" }
                                                }
                              }, function(reply){
                              var myObject = reply.qMeasureList.qItems;
                              
      
      
                                  var str = "";
                                  $.each(reply.qMeasureList.qItems, function(key, value) {
      
      
                                  var title = "";
                                  var description = "";
                                  var combined = "";
      
      
                                          title = JSON.stringify(value.qMeta.title) ;
                                          title = title.replace(/['"]+/g, '')
                                          description = JSON.stringify(value.qMeta.description) ;
                                          description = description.replace(/['"]+/g, '')
                                          combined = title + ": " + description;
                                          
                                          str +=   combined;
                                          str += "<br>"
                                          
                                  });
                              
                              
                              $element.html(str);
                              
                              });                                            
        }
        };     
      } );
      
      
        • Re: Listing all measures in an extension (Title, description, expression)
          Erik Wetterberg

          Hi Nathan,

          There should be a qDef somewhere that holds the definition. Use the debugger, set a breakpoint in your $.each function and inspect the value.

           

          The export data function exports the hypercube defined in your underlying generic object. Since you do not have a hypercube in your generic object it wont work.

           

          Hope this helps

           

          Erik

            • Re: Listing all measures in an extension (Title, description, expression)
              Nathan S

              Hey there,

               

              Thanks for the feedback. The problem I have is that the below is what the object looks like when I write it to the console.  I'm guessing then that I'm using the wrong object?  The documentation on all this is tricky to follow.

               

              {
                  "qInfo": {
                      "qId": "MU1",
                      "qType": "mashup"
                  },
                  "qSelectionInfo": {},
                  "qMeasureList": {
                      "qItems": [
                          {
                              "qInfo": {
                                  "qId": "AXDYc",
                                  "qType": "measure"
                              },
                              "qMeta": {
                                  "title": "TestMeasure",
                                  "description": "This is to test an extension",
                                  "tags": []
                              },
                              "qData": {
                                  "title": "",
                                  "tags": ""
                              }
                          },
                          {
                              "qInfo": {
                                  "qId": "jjqbKwm",
                                  "qType": "measure"
                              },
                              "qMeta": {
                                  "title": "GenericMeasure",
                                  "description": "'Here is another measure to test with'",
                                  "tags": []
                              },
                              "qData": {
                                  "title": "",
                                  "tags": ""
                              }
                          },
                          {
                              "qInfo": {
                                  "qId": "gPBjgP",
                                  "qType": "measure"
                              },
                              "qMeta": {
                                  "title": "ThirdMeasure",
                                  "description": "This is the description part of the measure",
                                  "tags": []
                              },
                              "qData": {
                                  "title": "",
                                  "tags": ""
                              }
                          }
                      ]
                  }
              }
              
              
              • Re: Listing all measures in an extension (Title, description, expression)
                Nathan S

                Hi there, my primary question has been answered, but I don't really understand what you mean by this

                 

                "The export data function exports the hypercube defined in your underlying generic object. Since you do not have a hypercube in your generic object it wont work."

                 

                Can you perhaps give more detail on this?  Can I include a hypercube in my generic object?  Been doing some reading around, but no luck thus far.

                  • Re: Listing all measures in an extension (Title, description, expression)
                    Erik Wetterberg

                    The underlying generic object is the one you define in your initialProperties in the extension. More on that here.

                     

                    You could define your measureList in initialProperties instead of with app.createGenericObject, and that might be a good idea, but since ther is no export method on the measureList, only on the hypercube, it would not make export work for you.

                     

                    You could also add a hypercube to your initialProperties and to your generic object, but the list of measures would not be in it so it would still not be exportable.

                     

                    Hope this helps

                     

                    Erik