Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
bryan_sng
Partner - Creator
Partner - Creator

Qlik sense extension load data without dimension

Hello guys,

Is there any way I can access data from the app data model without using dimensions?

I understand I can access data via layout.qHyperCube.qDataPages[0] if I add the necessary dimensions in.

I also tried initialproperties such as the following but could not find it anywhere in the layout variable.

define([], function () {

  return {

    version: 1.0,

    qHyperCubeDef: {

      qDimensions: ['mytestproperty1', 'mytestproperty2'],

      qMeasures: [],

      qInterColumnSortOrder: [],

      qInitialDataFetch: [{

        qWidth: 3,

        qHeight: 400

      }]

    }

  };

});

Do you guys have any advice? Thanks!

35 Replies
ErikWetterberg

Feels like createCube is the way to go. It allows you to send in a number of dimensions and measures, just make sure that you set the qWidth in qInitialDataFetch high enough. Since you only want to get the data once, and not set up a subscription, you should call destroySessionObject once you have got what you want.

So you would call the following:

  1. qlik.currApp(this) (you could do this only once and save the app object)
  2. make sure selection state is what you want, possibly make a selection
  3. createCube
  4. in the callback from createCube: destroySessionObject

Hope this helps.

Erik

bryan_sng
Partner - Creator
Partner - Creator
Author

That does sound like a viable solution! However by adding that single dimension expression, since it is not link to my other dimensions in the data model, it cause my datapage qMatrix to increase expotentially. Do you have any advice on how to overcome this issue?

bryan_sng
Partner - Creator
Partner - Creator
Author

This solution looks very promising as indeed I am now able to retrieve data without specifying dimension in my extension. There is a catch now as you mentioned, I need to set the qInitialDataFetch high enough. However the information that I need to retrieve is about 8000+ records. I read elsewhere that qlik sense initial data load seems to cap at around 1000 records. The following URL: How to use Backend API from Mashups? poster does have the same problem as me but with no solution, do you guys have any?

Alternatively, is there anyway to get only a single record based on a criteria? Since my requirement for this case is to display building information given a building id.

ErikWetterberg

Good that you are moving forward!

Perhaps you could try something like:

app.field("BUILDID").selectValues(["110033445566"],false,true);

before you create the hypercube to get the data.

Erik

bryan_sng
Partner - Creator
Partner - Creator
Author

Hmm, I tried the selectValues method and a little bit strange, it's working 90% of the time (90% of the time it retrieve data based on my criteria, 10% of the time it retrieve all 8000+ records). Below is an extract of my codes:

    var datas = [];

    var app = qlik.currApp(this);

    app.field("building_id").selectValues([41838777],false,true);

    app.createCube({

      qDimensions: qDimensions,

      qMeasures: [],

      qInitialDataFetch: [{

        qWidth: 10,

        qHeight: 500

      }]

    }, function(reply) {

      $.each(reply.qHyperCube.qDataPages[0].qMatrix, function(key, value) {

        datas.push(value);

      });

      app.destroySessionObject(reply.qInfo.qId);

      console.log(datas); // 90% filtered, 10% full

    });


Additionally, I realise what selectValues does is selecting that criteria in qlik sense current selection.

I'm just thinking if I already have some selections from other components, i would probably be retrieving data based on the combined criteria. Hmm, is there a way to create an app such that it does not use the current app to retrieve the data but using a temporary app instead so that I will not be messing with the current app selection?


ErikWetterberg

Hi,

There is a timing issue here apparently. Try:

app.field(...).selectValues(...).then(function(){

  app.createCube(...);

});

Should fix that problem...

Yes, it would affect selection state. You could restore it with app.back() after you get the data.

Another possible solution (which I haven't tried, so I can not promise you that it works) is using an alternate state. You could create it with app.addAlternateState and then use it both when you get the field and when you create the cube.

Erik

bryan_sng
Partner - Creator
Partner - Creator
Author

Hello Erik, you did it! addAlternateState was the way to go.

I am now able to get data from the data model without using dimension.

Here is an extract of my working codes in case any one have the same issue as me.

Once again, totally appreciate your help on this issue, thanks!

    getBackendData( [ 'building_id', 'product_name' ], 'building_id', [ 1234567 ] ).done(function(datas) {

      var match = datas[0];

      console.log(match); // this contains building id and product name information

    });

  function getBackendData(dimensions, fieldName, fieldValues) {

    var qDimensions = [];

    $.each(dimensions, function(index, dimension) {

      qDimensions.push({ qDef : { qFieldDefs : [dimension] } });

    });

    var datas = [];

    var deferred = $.Deferred();

    var alternateStateName = 'demo123832'; // some unique name would be good here

    var app = qlik.currApp();

    app.addAlternateState(alternateStateName).then(function() {

      app.field(fieldName, alternateStateName).selectValues(fieldValues, false, true).then(function() {

        app.createCube({

          qStateName: alternateStateName,

          qDimensions: qDimensions,

          qMeasures: [],

          qInitialDataFetch: [{

            qWidth: 10,

            qHeight: 500

          }]

        }, function(reply) {

          $.each(reply.qHyperCube.qDataPages[0].qMatrix, function(key, value) {

            datas.push(value);

          });

          app.destroySessionObject(reply.qInfo.qId).then(function() {

            app.removeAlternateState(alternateStateName);

          });

          deferred.resolve(datas);

        });

      });

    });

    return deferred;

  }

P.S. thanks to all other contributors too!

bryan_sng
Partner - Creator
Partner - Creator
Author

Hello Alexander, hmm u mention that you have done google maps extension before, just wondering are you able to capture snapshot and retains the current state of the map (like zoom level, feature selection, etc)?

Alexander_Thor
Employee
Employee

Currently I only do markers/clusters but yes and sort of


My map scales to the appropriate zoom level to fit the available markers. So if a user snapshots a map with some data selected then the map will zoom to fit those markers in a story.

bryan_sng
Partner - Creator
Partner - Creator
Author

Hmm just to confirm, let's assume that you have a marker at USA, then you pan the map to Europe and do a snapshot, can I assume that when you view the snapshot in a story, you will still be looking at USA?