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: 
BradMazurek
Contributor II
Contributor II

Understanding QField.selectValues()

I'm new to Qlik and it's been almost 10 years since I programmed in JavaScript, so please bear with me...I'm trying to make an extension.

I'm having several issues with QField.selectValues(). In the course of trying to diagnose my problem, I've encountered several things I'd like to have clarified.

A selectValues() call doesn't seem to be idempotent. If I make a call once, it works. If I make the same call twice in a row, nothing happens. Why? Logically, shouldn't it be idempotent? (I'm looking to understand why so I can integrate the rationale into my mental model.)

By way of example, consider the snippet below. If there was only one selectValues() below it works find. A second causes no selection to occur. A third causes it to be selected. Is selectValues() really a toggle of some sort? If so, why?

$("#" + utils.fieldToId(curField)).on( "click", "#" + id, function() {
   thisApp.field("First Name").selectValues(["Brad"], true, true);
   thisApp.field("First Name").selectValues(["Brad"], true, true);
   thisApp.field("First Name").selectValues(["Brad"], true, true);
});​​

When calling selectValues() there seems to be a difference between passing in a Qlik-generated row object with a qText property and a generic object with a qText property. Why? If I pass in a Qlik object it fails. For example:

 

thisApp.field(value.qName).rows.forEach( function(row) {
...
thisApp.field(curField.qName).selectValues([row], true, true); //does not work
thisApp.field(curField.qName).selectValues([{qText:row.qText}], true, true); //works​

 

The code in my first example works. I see several questions where answers seems to indicate that my field name should have been "[First Name]" because it has a space in it. What are the rules around this? With out the square braces am I playing with fire? When programming for an unknown field name, is it programmatically best practice to always include the square braces? If so, isn't that something the API do that for us?

Thank you.

1 Solution

Accepted Solutions
ErikWetterberg

Hi,

Perhaps you should start by reading the docs:

https://help.qlik.com/en-US/sense-developer/September2019/Subsystems/APIs/Content/Sense_ClientAPIs/C...

Second parameter, which is set to true in all your examples is toggle, which means that it will deselect an already selected value. If you don't want that set the parameter to false, or omit it, since false is the default.

View solution in original post

2 Replies
ErikWetterberg

Hi,

Perhaps you should start by reading the docs:

https://help.qlik.com/en-US/sense-developer/September2019/Subsystems/APIs/Content/Sense_ClientAPIs/C...

Second parameter, which is set to true in all your examples is toggle, which means that it will deselect an already selected value. If you don't want that set the parameter to false, or omit it, since false is the default.

BradMazurek
Contributor II
Contributor II
Author

Fair for the first point. I was deep enough in diagnosing other problems that I didn't return to the top level and reread the docs. Thank you.

I'll ask the other questions again.