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 value of a variable with a widget?

Hello everybody,

I want to create a widget which gets and sets the value of a variable by using a drop-down list in Qlik Sense.

I could realize a drop-down list which sets a variable by using the setContent method from the Variable API. However, I have a problem with getting the value of a variable since the appropriate methods from the Variable API use a callback function. Is there a possibility to realize such a widget?

I am new to Qlik Sense development and I have some basic knowledge in AngularJS.

Thanks a lot in advance for your responses.

Kind regards,

Leon

1 Solution

Accepted Solutions
Not applicable
Author

@Stefan: Thank you for your response! I am looking forward to the new version of Qlik Sense.

Such a widget can also be developed using Qlik Sense 3.0. I developed the widget using the following method.

To set the value of a variable, use a html button with ng-click="app.variable.setContent('MYVAR','1');".

To get the value of a variable, create an input field in the properties (e.g. named myvar) of the widget and type there =$(MYVAR). You can use this value by referencing settings.myvar.

This works if the variable has a nummeric value.

Here is an example:

<div>

  <select ng-model="selectVal" ng-init="opt=settings.selVarValue" ng-change="app.variable.setContent(settings.selVarName, selectVal);" class="lui-select">

   <option ng-selected="opt==1" value="1">{{settings.optLabel1}}</option>

   <option ng-selected="opt==2" value="2">{{settings.optLabel2}}</option>

   <option ng-selected="opt==3" value="3">{{settings.optLabel3}}</option>

  </select>

</div>

View solution in original post

5 Replies
1000qlik
Partner - Contributor III
Partner - Contributor III

Hi Leon,

I am also interested in knowing if it possible to use widgets in order to achieve such behavior.

Did you find anything?

Many thanks.

Best regards,

Robert

Stefan_Walther
Employee
Employee

Hi,

this can currently not be achieved (based on Widget in Qlik Sense 3.0). But we are soon publishing a new API in Qlik Sense 3.1 that will allow you to get to the desired result.

Stay tuned!

Regards

Stefan

Not applicable
Author

@Stefan: Thank you for your response! I am looking forward to the new version of Qlik Sense.

Such a widget can also be developed using Qlik Sense 3.0. I developed the widget using the following method.

To set the value of a variable, use a html button with ng-click="app.variable.setContent('MYVAR','1');".

To get the value of a variable, create an input field in the properties (e.g. named myvar) of the widget and type there =$(MYVAR). You can use this value by referencing settings.myvar.

This works if the variable has a nummeric value.

Here is an example:

<div>

  <select ng-model="selectVal" ng-init="opt=settings.selVarValue" ng-change="app.variable.setContent(settings.selVarName, selectVal);" class="lui-select">

   <option ng-selected="opt==1" value="1">{{settings.optLabel1}}</option>

   <option ng-selected="opt==2" value="2">{{settings.optLabel2}}</option>

   <option ng-selected="opt==3" value="3">{{settings.optLabel3}}</option>

  </select>

</div>

Not applicable
Author

Leon, are you sure API app.variable.* works in widgets?

My very simple code:

<lui-select x-model="value" ng-change="app.variable.setContent('varMeasure', '1');">

  <option value="1">First</option>

  <option value="2">Second</option>

  <option value="3">Third</option>

</lui-select>

leads to js error:

Cannot read property 'getVariableByName' of undefined...

JShum
Contributor II
Contributor II

I am trying to get this to work in a widget

<div class="lui-input-group">
<input class="lui-input-group__item lui-input-group__input lui-input" value={{settings.property4}} ng-change=app.variable.setContent('jtest','did I do it')></input>
</div>
The default value gets set by the variable but I can not get the change in the input box to be reflected back in the in the variable

Does it currently work?  Has anyone managed to get this to work?   I do not believe it works for the select ether