6 Replies Latest reply: Dec 21, 2016 6:41 AM by Fernando Tonial RSS

    How to get the current selections from a QlikSense object within a mashup?

      I'm new to QlikSense and can't figure out the right syntax to get the selected items from a qvobject.

       

      Below is the code that i'm using (for testing purposes i'm using qv mashup with qv desktop):

       

      I can select all the items with this code (see "this works", but I can't extract the selected items to a variable (see "this doesnt work")

       

      Can anybody help me with the right code syntax?

       

      <script type="text/javascript">
      function testSelection() {
        require( ["js/qlik"], function ( qlik ) {
        var app = qlik.openApp('report.qvf', config);
        //this works:
        //app.field("OrganisatieNiveau3").selectAll();  
        
        // this doesnt work:
        //var test = app.getObject('CurrentSelections','CurrentSelections').GetSelected();
        //var test = app.field("OrganisatieNiveau3").GetSelected();
        //var test = app.field("OrganisatieNiveau3").Data.GetSelected();
        //var test = app.Data.GetSelected();
        } );  
      }
      </script>
      <a href="#" onclick="testSelection()">test selection</a>
      
      
      
      
      
        • Re: How to get the current selections from a QlikSense object within a mashup?
          Thomas Lindackers

          You need the App.getList Method for that see Example bellow

           

          app.getList("CurrentSelections", function(reply) {

           

          selectionslist ="";

          var mySelectedFields = reply.qSelectionObject.qSelections;

          var mySelectedFields_arrayLength = mySelectedFields.length;

          for (var i = 0; i < mySelectedFields_arrayLength; i++) {

          if(mySelectedFields[i].qLocked==true) {

            icon = 'lock'

          } else {

            icon = 'unlock';

          }

           

          var text =  "";

          text =  '<div class="row ">';

           

          text += '<div class="col-s1">' + mySelectedFields[i].qField;

          text += '</div> <div class="col-s2">';

          text += ' <div id="bnBoSeFieldSelect' + i + '"> </div>';

          text += ' <span name="'+ mySelectedFields[i].qField +'" class="deleteSelection"> <i class="fa fa-trash"></i> </span>';

          text += ' <span name="'+ mySelectedFields[i].qField +'" class="'+ icon +'Selection"> <i class="fa fa-'+icon+'"></i> </span>';

          text += '</div> <div class="col-s3">';

           

           

          //loop through selected field values

          var currentFieldValues = mySelectedFields[i].qSelectedFieldSelectionInfo

          var currentFieldValues_arrayLength = currentFieldValues.length;

           

           

          for (var y = 0; y < currentFieldValues_arrayLength; y++) {

            if(y==0) {

              text += currentFieldValues[y].qName;

            } else {

              text += ", " + currentFieldValues[y].qName;

            }

          }

           

           

          text += "</div></div>"

           

           

          if(i==0) {

            selectionslist = text;

          } else {

            selectionslist += text ;

          }

           

          }

            • Re: How to get the current selections from a QlikSense object within a mashup?
              Fernando Tonial

              Hello Thomas ,

               

              My knowledge in javascript is basic.

               

              I'm using a code similar to yours, but it's displaying at most 6 values in each selected field, I'd like to display all of them.

              When we select all the values of the field that has more than 6 is without appearing.

              Can you help me?

               

              My Code:

               

              var contMes = 0;

              var contAno = 0;

              app.getList("CurrentSelections", function(reply) {

                var contAnoAux = 0;

                var contMesAux = 0

                selectionslist ="";

                var mySelectedFields = reply.qSelectionObject.qSelections;

               

                //loop through selected fields

                var mySelectedFields_arrayLength = mySelectedFields.length;

                for (var i = 0; i < mySelectedFields_arrayLength; i++) {

               

                var text = mySelectedFields[i].qField + " ";

                if( mySelectedFields[i].qField == "Ano")

                {

                contAnoAux += 1;

                }

                if(mySelectedFields[i].qField == "Mês"){

                contMesAux += 1;

                }

               

                if(mySelectedFields[i].qLocked==true) {

                var labeltype = 'label label-warning'

                } else {

                var labeltype = 'labelItem';

                }

               

                    //loop through selected field values

                var currentFieldValues = mySelectedFields[i].qSelectedFieldSelectionInfo

               

                var currentFieldValues_arrayLength = currentFieldValues.length;

               

                for (var y = 0; y < currentFieldValues_arrayLength; y++) {

               

                //text += currentFieldValues[y].qName + " ";

               

                text += "<span class='label " + labeltype + "'>" + currentFieldValues[y].qName + "</span> ";

                //put the field names into a variable

               

               

                }

                if(i==0) {

                selectionslist = text;

                } else {

                selectionslist += text;

                }

               

                //add the complete string for this field to an array.

               

                }

                if(contMesAux > 0){

                contMes  = 1;

                }

                else{

                contMes  = 0;

                }

                if(contAnoAux > 0){

                contAno  = 1;

                }

                else{

                contAno  = 0;

                }

               

                $("#myselections").html(selectionslist);

               

               

                if(selectionslist){

               

                if(contAno == 0 || contMes ==0)

                {

                 $('.clean').hide();

                 $(".resultado").hide();

                 $('.aviso').show();

                }

                else{

                 $('.clean').show();

                 $(".resultado").show();

                 $('.aviso').hide();

                }

               

                }

                 

                else

                {

                 $('.clean').hide();

                 $(".resultado").hide();

                 $('.aviso').show();

                }

                   });

            • Re: How to get the current selections from a QlikSense object within a mashup?
              Sangram Reddy

              You can even make use of this code to get all the current selections:

               

              var currentSelection = App.GetCurrentSelection();

              foreach (var selectedField in currentSelection.selections) {

              // you will get the field name in this variable Console.WriteLine("Field: " + selectedField.Field);

              // you will get the field Selections in this variable Console.WriteLine("Selected values : " + selectedField.Selected);

              }


              Hope this helps!

              Sangram Reddy.