Skip to main content

Integration, Extension & APIs

Discussion board where members can learn more about Integration, Extensions and API’s for Qlik Sense.

Announcements
QlikWorld 2023, a live, in-person thrill ride. Save $300 before February 6: REGISTER NOW!
cancel
Showing results for 
Search instead for 
Did you mean: 
nsm1234567
Creator II
Creator II

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

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);

                       

                        });                                           

  }

  };    

} );

1 Solution

Accepted Solutions
ErikWetterberg

Hi Nathan,

You're right, this is not well documented. Some experiments gave me the answer, you need to add "/qMeasure" to the qData object, something like this:

"qMeasureListDef": {

  "qType": "measure",

  "qData": {

       "title": "/title",

       "tags": "/tags",

       "measure": "/qMeasure"

  }

}

I have only tried this in the Engine API explorer, but it should work in javascript methods too.

Hope this solves your problem.

Erik

View solution in original post

6 Replies
ErikWetterberg

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

nsm1234567
Creator II
Creator II
Author

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": ""

                }

            }

        ]

    }

}

ErikWetterberg

Hi Nathan,

You're right, this is not well documented. Some experiments gave me the answer, you need to add "/qMeasure" to the qData object, something like this:

"qMeasureListDef": {

  "qType": "measure",

  "qData": {

       "title": "/title",

       "tags": "/tags",

       "measure": "/qMeasure"

  }

}

I have only tried this in the Engine API explorer, but it should work in javascript methods too.

Hope this solves your problem.

Erik

nsm1234567
Creator II
Creator II
Author

That worked!  Thanks so much.  I'd have never figured that out.

nsm1234567
Creator II
Creator II
Author

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.

ErikWetterberg

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