Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
fabian3684386
Contributor III
Contributor III

QlikSense Selections API inconsistent behaviour toggling .clearAll() and then .selectValues() CapabilityAPI

I use this vanilla JavaScript on click event handler with HTML5 data-* attributes to trigger selections when clicking a certain DOM element interactive button:

 

 

 

console.log('data-field', this.getAttribute('data-field'), 'data-value', this.getAttribute('data-value')); 

document.app.field(this.getAttribute('data-field')).clear();

document.app.field(this.getAttribute('data-field')).selectValues([this.getAttribute('data-value')], true, true);

 

 

 

 Goal is to clear any previously made selections in a field and then on top of that / after that select only one exact value (the one passed via data-value attribute) in the data-field.

However, I suspect I did something wrong with these API calls because what happens is sometimes the .clear() does not execute correctly and the user is left with the previous active selection + the selectValues selection.

Clicking multiple times after waiting a certain time then does what is supposed to be achieved in one click.

Is this due to the asynchronous nature of the API calls and do I need some kind of callback?

Or am I using the API wrong?

What are the true, true flags used for? I do not understand these details shared in the docs:

 

 

toggle
Type: Boolean

Optional.

If true, toggle selected state.

softlock
Type: Boolean

Optional.

If true, locked selections can be overridden.

 

 

(c.f. https://help.qlik.com/en-US/sense-developer/August2023/Subsystems/APIs/Content/Sense_ClientAPIs/Capa...)

Can someone elaborate, please?

Thanks!

Labels (2)
1 Solution

Accepted Solutions
alex_colombo
Employee
Employee

Hi @fabian3684386 , this is happening because you are not waiting clear method to be perfomed on engine side. clear method returns a promise, so you have to implement this with await or with ".then". Here info on the clear method and what is returning.
About the flag parameters, toggle means that if the same selections that you want to apply has been already applied, then you will not select values, but values will be removed from the current selections. Other way around, if you dont have any selections applied on the field, then your selections will be applied. 
Softlock is used for locking the selections. You can replicate this behaviour opening a selection from current selection bar and then click on lock icon

View solution in original post

1 Reply
alex_colombo
Employee
Employee

Hi @fabian3684386 , this is happening because you are not waiting clear method to be perfomed on engine side. clear method returns a promise, so you have to implement this with await or with ".then". Here info on the clear method and what is returning.
About the flag parameters, toggle means that if the same selections that you want to apply has been already applied, then you will not select values, but values will be removed from the current selections. Other way around, if you dont have any selections applied on the field, then your selections will be applied. 
Softlock is used for locking the selections. You can replicate this behaviour opening a selection from current selection bar and then click on lock icon