Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Arvydas
Partner - Contributor
Partner - Contributor

Extension export: exception when fetching master dimension's colors

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 sheetNormal sheet

This is a result of PNG export:

Exported PNGExported 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

0 Replies