If you’ve ever built an extension in Qlik Sense focused on data visualization, you know how cool it is to harness the power of the Qlik associative engine. It is important for such visualizations to integrate with the user experience and really feel like Qlik—both in style and functionality.
My path started by trying to “turn on” the export functionality for a table-like extension I was developing. The Qlik help pages helpfully told me to add a property named “export” to the support object within the Qlik extension object and set it to true.
After adding snapshot, export, and exportData to my extension object, my visualization had right-click buttons to Snapshot, Export as Image, Export as PDF, and Export to Excel. However, only Export to Excel functioned correctly (to more experienced Qlik readers, this shouldn’t be a shock; Export to Excel is done by the Qlik engine and only relies on the dimensions and measures of a visualization). Yet I was surprised to discover that the other three options resulted in blank exports and blank areas in my Data Stories.
I was flummoxed. The Qlik help pages made it seem like all you needed were those settings. Googling “Qlik sense extension export” yielded only the same simple help pages or other unanswered pleas for help. I could not find documentation, examples, or anything else that seemed of use online (hopefully this post might help others if they have the same issue).
Debugging the issue became a little like wandering in the dark, because console logs and errors do not display normally on the browser when exporting to PDF/Image or when adding a snapshot to a Story.
However, I knew it could be done, as some very simple extensions correctly perform exports or snapshots. So, I started with the simplest possible version of my table-like extension then added lines one at a time until the export/snapshot broke. When things “broke”, I tweaked things until I got them working.
The full impact of my discovery and instructions for working with it are logged below in The Stuff.
First off, all PDF/Image exports are the result of Qlik taking a Snapshot of a visualization. If an extension can be correctly exported, it should also correctly function as a Snapshot in Story Mode. The converse of that statement is also true.
The BackendApi is somewhat documented at the website listed above.
For pdf/img exports and snapshots, the variable named backendApi becomes a SnapshotAPI. To reiterate an earlier point, all PDF/Image exports are created by Qlik creating and using a Snapshot of the target visualization. SnapshotApi supports:
SnapshotApi is mostly undocumented at the time of this article.
The first step to resolving these differences is to programmatically find out which API is currently being used. I was hoping that there would be a handy ‘isSnapshotApi’ property on the object named backendApi, but there was not. I did find one property that only existed on BackendApi’s, named ‘isHyperCube’. Since I code my extensions in AngularJS, my Boolean check looks like this:]
By using the Boolean isSnapshot, my code can now adapt to functioning in normal mode and in snapshot mode.
This example also shows how one of the key data functions, getData(), behaves differently in a SnapshotApi. When not in snapshot mode, getData() can be called with parameters to paginate through the data in a visualization. In the case for isSnapshot, getData takes no parameters and will always return a single page of data containing the hypercube that existed when the snapshot was taken.
Configuring an extension to export and snapshot correctly can be a chore, but it is possible once you understand that some things change between a visualization’s normal mode and its snapshot mode. The result is a fully functional visualization that fits well with Qlik’s visualization suite.