HerrJohr
HerrJohr

Reputation: 529

How to develop a Qlik Sense Extension that works in Mashups with multiple apps

My Extension doesn't work in Mashups that load objects from multiple apps.

It seems to work, when my extension is from the app that is loaded first by Qlik Sense. But if my Extension is in two different Apps, one of those works and the other doesn't.

Upvotes: 0

Views: 431

Answers (1)

HerrJohr
HerrJohr

Reputation: 529

TL;DR

Don’t use:

qlik.currApp()

Do use

qlik.currApp(this)

to make your Extension support being used in Mashups with multiple apps.

Detailed Explaination

If you need to call functions on the app behind the extension object, then you probably use qlik.currApp();

qlik.currApp() gives you the current App that is loaded. That is fine if only one app is loaded into an mashup. But if there are multiple apps, qlik.currApp() just gives you the first app, that it loaded.

According to the Qlik Sense Documentation on the currApp method:

qlik.currApp(reference)

Gets a reference to the current app. Use the currApp method in an extension to get a reference to the app currently displayed.

Image you have two apps: A and B. A is loaded first. Then you include also an object from App B into the Mashup. But the type of object is an Extension and that extension uses qlik.currApp(), it is likely, that this object won’t work properly. That extension will call functions on app A even though it is from app B.

You can tell Qlik which app you want to reference. For that you need the reference to the extension instance. You get it as the this reference inside your paint method in the Extension Code:

paint: function(§element, layout){
    var app = qlik.currApp(this);
    // [...]
}

In case you have another closure inside the paint function, you need to save the this reference. If not, the this reference gets overwritten by the inner function object. A common case is to save the this reference to that:

paint: function(§element, layout){
    var that = this;

    loader.load(assets, function(){
        var app = qlik.currApp(that);
        // [...]
    });
}

Upvotes: 1

Related Questions