Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

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>

9 Replies
Not applicable
Author

Anybody? It should be possible right?

awhitfield
Partner - Champion
Partner - Champion

Hi,

.qvf is a Qlik Sense file NOT Qlikview

Andy

Not applicable
Author

You're right, my mistake I mean Qliksense, thanks for noticing.

I'll move my question to the right place. (my question remains the same)

Not applicable
Author

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.qLocked==true) {

  icon = 'lock'

} else {

  icon = 'unlock';

}

var text =  "";

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

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

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

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

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

text += ' <span name="'+ mySelectedFields.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.qSelectedFieldSelectionInfo

var currentFieldValues_arrayLength = currentFieldValues.length;

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

  if(y==0) {

    text += currentFieldValues.qName;

  } else {

    text += ", " + currentFieldValues.qName;

  }

}

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

if(i==0) {

  selectionslist = text;

} else {

  selectionslist += text ;

}

}

reddy-s
Master II
Master II

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.

fernando_tonial
Partner - Specialist
Partner - Specialist

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.qField + " ";

  if( mySelectedFields.qField == "Ano")

  {

  contAnoAux += 1;

  }

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

  contMesAux += 1;

  }

  if(mySelectedFields.qLocked==true) {

  var labeltype = 'label label-warning'

  } else {

  var labeltype = 'labelItem';

  }

      //loop through selected field values

  var currentFieldValues = mySelectedFields.qSelectedFieldSelectionInfo

  var currentFieldValues_arrayLength = currentFieldValues.length;

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

  //text += currentFieldValues.qName + " ";

  text += "<span class='label " + labeltype + "'>" + currentFieldValues.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();

  }

     });

Don't Worry, be Qlik.
Anonymous
Not applicable
Author

Checked show selection bar from bottom of the mashup and automatic code add in your HTML or <div id="CurrentSelections" class="qvobjects" style="position:relative; top:0; left:0; width:100%; height:35px; z-index:1010;"> </div> past this code.

Image 1.png

ajunaidm
Partner - Contributor
Partner - Contributor

If I have to close a singe selection then what can I do for this???

harithadogiparthi505
Contributor III
Contributor III

Can you please have the html code also and in this particular code can we remove selections?