Qlik Community

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

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

Re: How to get the value of a variable with a widget?

@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>

4 Replies
bobbyinch
New Contributor II

Re: How to get the value of a variable with a widget?

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

Employee
Employee

Re: How to get the value of a variable with a widget?

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

Re: How to get the value of a variable with a widget?

@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

Re: How to get the value of a variable with a widget?

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...

Community Browser