Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
It seems during export only, `app.getObject('ColorMapModel_' + libraryId)` (where libraryId is master library dimension's id), fails with an exception "cannot read promise of undefined", which arises from qlik internals. It fails both in enterprise (June 2019) and desktop environments (November 2020). My question is how do I fix this, or what workarounds could I use to get it to work? This is how extension looks on normal sheet view: Normal sheet
This is a result of PNG export:
Exported PNG
Here is full extension code:
define(['jquery', 'qlik'], function ($, qlik) {
function loadDimensionColors(extensionReference, layout) {
var app = qlik.currApp(extensionReference);
if (!app)
return qlik.Promise.resolve('qlik.currApp(extensionReference) returned null');
var libraryId = layout.qHyperCube.qDimensionInfo[0].qLibraryId;
if (!libraryId)
return qlik.Promise.resolve([]);
try {
return app.getObject('ColorMapModel_' + libraryId) //exception thrown here
.then(function(colorMapObj) {
return colorMapObj.layout.colorMap.colors;
});
} catch (e) {
return qlik.Promise.reject(e);
}
}
return {
definition : {
type : 'items',
component : 'accordion',
items: {
dims : {
uses : 'dimensions',
min : 1,
max : 1
}
}
},
support: {
export: true
},
paint: function ($element, layout) {
$element.html('');
return loadDimensionColors(this, layout)
.then(function(colorsOrError) {
if (Array.isArray(colorsOrError)) {
colorsOrError.forEach(function(c) {
var div = $('<div/>').text(c.value).css('background-color', c.baseColor.color);
$element.append(div);
});
} else {
var div = $('<div/>').text(colorsOrError);
$element.append(div);
}
})
.catch(function(e) {
$element.append($('<div/>').text(e.stack? e.stack : e));
});
}
};
});
I attach zip containing extension and a sample application using it. Thanks in advance!
Arvydas