Qlik Community

Qlik Sense Integration, Extensions, & APIs

Discussion board where members can learn more about Integration, Extensions and API’s for Qlik Sense.

MarcelMerz
New Contributor

app.field().getData() - Databinding

Hi,

i`m struggling building a qlik sense Extension. For my extension I need to get all values of the Datafield "Position". I searched in the API and found the app.field().getData() Method.

I implemented this Method in my paint-Function with the matching Data-Binding.

paint: function ($element, layout) {
     //add your rendering code here
     $element.html( "Test-Paint" );
	//needed for export
var field= layout.propsField; var field_values = app.field(field).getData(); console.log("---------------------"); field_values.OnData.bind( function(){ console.log("test"); field_values.rows.forEach(function(row){ }); ); return qlik.Promise.resolve(); }

 For test purposes i added a Console.log("test") to check how often the method is called. I need to execute this function in the Paint Method.

The Problem is that this method is called multiple times.

For example if i load the worksheet the first time it print "test" only once. Thats fine. But if i change my worksheet, come back again to the sheet with my extension it print "test" twice. If i come back a third it print "test" three times. And so on. 

So when i switch the Sheet ten times it`ll print ten times. 

The output looks like:

----------------------  (1. Time)
 Test
----------------------  (2. Time)
Test 
Test
----------------------  (3. Time)
Test
Test
Test

Is that a bug of Qlik sense or do i have a different understanding of the Databinding-Function?

2 Replies
Employee
Employee

Re: app.field().getData() - Databinding

Hi @MarcelMerz,

This is not a bug, depending on your extension, the paint method will run each time a refresh or a data model change is triggered.

For your case you should probably use the `mounted` method => https://help.qlik.com/en-US/sense-developer/November2018/Subsystems/APIs/Content/Sense_ClientAPIs/Ex...

It runs once when the object is initializing.

Highlighted
erik_wetterberg
Honored Contributor

Re: app.field().getData() - Databinding

That's beacuse every time the paint method is called a new function is bound to the OnData event. The framework will probably cache the object returned from app.field('..').getData() for you, so it will only be created once even though you try to create it over and over again, but a new anonymous function is bound every time paint() is called.

Avoid calling API method in your rendering code: instead set up object properties so that the layout contains what you need for rendering.

Erik Wetterberg
https://extendingqlik.upper88.com/