1 Reply Latest reply: Mar 16, 2017 9:58 AM by Richard Bartley RSS

    API reading and applying selection issue and looping

    Richard Bartley

      Hello all,


      I am having a couple of issues at the moment with using the APIs to read and make selections.  The scenario is as follows:  I have a  mashup featuring a number of dimensions and a chart.  Because some of the dimensions are mutually exclusive, I have created an unlinked dimension so that the values in the filter panel will not be affected by the selection of the other dimensions.  This works fine in that all the values I would expect to see in the filter list are displayed.  However, I then want to apply the values selected in the unlinked dimension filter to the dimension in the chart and this is where things go wring in that:


      1) The code seems to keep looping even though I apply the filter outside of the $.each loop and use a "return true" to escape the loop.

      2) The selection only works if I select one value or if I hard code the selections rather than using value.qSelected (I tried formatting the string to be the same as the hard-coded values but it still doesn't seem to work, so I'm obviously doing something wrong).



      This is what I am doing:


      1) Set up mouseup  event on the div containing the filter Qlik filter panel (I have also tried with the click event) which calls function

      $('#filterPigAndCereals').mouseup(function (obj){
        var strCerealsFilter;
        strCerealsFilter = filterCerealCategory(qlik,app); 


      2) Create a function to read the selection object to find out which fields and values have been selected and if they refer to the field I am interested in then filter the dimension in the chart.


      function filterCerealCategory(qlik,app)
        var intSelectedCerealsValues=0;
        var objSelectionsList = app.getList("SelectionObject", function(reply){
        $.each(reply.qSelectionObject.qSelections, function(key, value) {
        var field = value.qField;  //The field name
        var numSelected=0;
        if(field=="Cereals Category Price Unlinked")
        numSelected= value.qSelectedCount;  //Number of selections in field
        selections = value.qSelected;
        if(field=="Cereals Category Price Unlinked" &&  numSelected>0)
        return true;
        }); //end each qSelections
        if(intSelectedCerealsValues > 0)
        app.field("Cereals Category (Price)").selectValues([selections]);
        return true;


      Any help would be much appreciated.


      Thanks in advance.