14 Replies Latest reply: Dec 8, 2017 11:19 AM by Paul Calvet RSS

    Hypercube callback after every selection

    Thomas Pessato

      Hello all,

       

      I'm creating a mashup using hypercube.

       

      I'm trying to use a hypercube to get value 'Year', from a expression using the Qlik Engine. After that, I want to make an automatic selection on the field 'Year'.


      So ok, my hypercube is working and calling my callback function. Then I set my selection on the right field. And it works.


      But I realized that the callback function keeps getting called after every selection made on the mashup. Since my data doesn't change, I don't want it to happen. It's unecessary.

       

       

      I managed this issue by:

       

      1. Placing a flag like:

       

      var hypercubeDone = false;

      function callback(reply, app) {

              if(hypercube) {

                    return;

                }

              // do some stuff

              hypercubeDone = true;
      }

       

      in my JavaScript file.

      But that doesn't solve my problem of calling this method multiple times. So I tried another solution...

       

      2. Destroying the hypercube after the call:

       

      But don't know if this is a good practice. So I tried to find another way.

       

       

       

      I don't want this to happen, since it is not necessary. Is there a right way to prevent this?

       

       

      Thanks!!

        • Re: Hypercube callback after every selection
          Erik Wetterberg

          Hi,

          You could use evaluate Evaluate method ‒ Qlik Sense instead.

           

          Erik Wetterberg

          • Re: Hypercube callback after every selection
            Francis Kabinoff

            Just use the promise instead of the callback.

             

            app.createCube({

              // stuff

            }, function(layout) { //this is the callback, just dont use it })

             

            instead do this

             

            app.createCube({

            // stuff

            }).then(function(object) { // here you'll get the object, which has layout on it, and this will only run once })

              • Re: Hypercube callback after every selection
                Paul Calvet

                Hi Francis,

                 

                How can I retrieve the value of the expression in the promise ?

                What code should I write ?

                When I look at the "object" in the chrome debug, I don't find the value of the expression.

                 

                app.createCube({

                        "qInitialDataFetch": [

                            {

                                "qHeight": 20,

                                "qWidth": 1

                            }

                        ],

                        "qDimensions": [],

                        "qMeasures": [

                            {

                                "qDef": {

                                    "qDef": "max({$<[Year Month]={$(=maxstring([Year Month]))}>}Month)"

                                },

                                "qLabel": "GetPlatform",

                                "qLibraryId": null,

                                "qSortBy": {

                                    "qSortByState": 0,

                                    "qSortByFrequency": 0,

                                    "qSortByNumeric": 0,

                                    "qSortByAscii": 1,

                                    "qSortByLoadOrder": 0,

                                    "qSortByExpression": 0,

                                    "qExpression": {

                                        "qv": " "

                                    }

                                }

                            }

                        ],

                        "qSuppressZero": false,

                        "qSuppressMissing": false,

                        "qMode": "S",

                        "qInterColumnSortOrder": [],

                        "qStateName": "$"

                        }).then(function(object) {

                           

                            // here you'll get the object, which has layout on it, and this will only run once

                             What shoul I do write here ?

                        });

                 

                Thanks !

                 

                Paul

                  • Re: Hypercube callback after every selection
                    Erik Wetterberg

                    Hi Paul,

                    Don't use a Hypoercube if you only want one expression evaluated, use a ValueExpression instead. Also note that createCube will create a subscription, so the expression will be recalculated when there are changes in selection state that affects the result. By using the promise instead of the callback you will not be notified, by the calculation will be made anyhow. Evaluate is really better for a one-time calculation.

                     

                    Hope this helps

                     

                    Erik Wetterberg

                      • Re: Hypercube callback after every selection
                        Paul Calvet

                        Thanks Erik,

                         

                        I want to select the last month available when the user open the mashup.

                         

                        I use the app.field function to do this :

                        app.field('Month').selectValues([11], false, true);

                         

                        I try with this code, but it doesn't work...

                         

                        app.createGenericObject( {

                                    fields: {

                                    qValueExpression:{"qExpr":"=max({$<[Year Month]={$(=maxstring([Year Month]))}>}Month)"}

                                    }                      

                                }).then (function ( object ) {

                                    var str = object.fields;

                                    app.field('Month').selectValues([str], false, true);

                                    console.log(str);

                                });

                         

                        Thanks,

                         

                        Paul