Qlik Community

Qlik Design Blog

All about product and Qlik solutions: scripting, data modeling, visual design, extensions, best practices, etc.

Employee
Employee

Export Data, Image and Pdf from Qlik Sense September 2018 Capability API

In every new Qlik Sense release, we see some cool additions and features that make our life easier. All of the major ones, are discussed here, https://community.qlik.com/blogs/qlikproductinnovation/2018/09/11/qlik-sense-september-2018-has-arri...‌, but for those that work a lot with the Capability Api, there are 3 very much desired and long expected features: exportData, exportImg and exportPdf. With these, you can export any embedded object from your mashup in the above formats. You can also customize them by passing the desired options.

 

Below are the links to the help files so you can experiment more.

 

ExportData

https://help.qlik.com/en-US/sense-developer/September2018/Subsystems/APIs/Content/Sense_ClientAPIs/C...

 

ExportImg

https://help.qlik.com/en-US/sense-developer/September2018/Subsystems/APIs/Content/Sense_ClientAPIs/C...

 

ExportPdf

https://help.qlik.com/en-US/sense-developer/September2018/Subsystems/APIs/Content/Sense_ClientAPIs/C...

 

You can view all of these in action by visiting the qdt-components webpage

React template with qdt-components

 

Best,

Yianni

31 Comments
Partner
Partner

I only got ExportData to work

Like this:

app.getObject('QV01', 'MYID').then( function( vizModel ) {

      vizModel.exportData(settings).then(function( reply ) { 

          console.log(reply);

      });

  });

But the other two methods doesn't work. What do I have to change in above code to get it work?

Allso your React template is broken.

0 Likes
2,106 Views
Employee
Employee

Here is the code with their settings on all of the 3 methods.

https://github.com/qlik-demo-team/qdt-components/blob/master/src/components/QdtButton.jsx

2,106 Views
Partner
Partner

Thanks for you reply Yianni!

I checked at your code and it seemed to me that all three methods are being used the same way except for different options.

If I try to log them to the console I only find exportData. Is the other two methods on a different level?

   app.getObject('QV01', 'MYID').then( function( vizModel) {

       console.log(vizModel.exportData); // returns function

       console.log(vizModel.exportPdf);   // returns undifined

       console.log(vizModel.exportImg);   // returns undifined

  });

0 Likes
2,106 Views
Partner
Partner

Is this also available in the .NET SDK? Have been waiting for this

0 Likes
2,106 Views
Partner
Partner

Is it possible to export an entire sheet using these methods?

0 Likes
2,106 Views
Employee
Employee

Hello Jens

This methods are bind just to an object's model

0 Likes
2,106 Views
Employee
Employee

Hello Roy,

Check your server TempDirectory if the files are created. It could be permission issues

C:\ProgramData\Qlik\Sense\Repository\TempContent

Also check your security rules if the anon users can exportApp contents

0 Likes
2,106 Views
Employee
Employee

Thank you Roy, The url to the export data is wrong. It has qdt-components in... fixing...

0 Likes
2,106 Views
Partner
Partner

Within the Qlik Sense App Ui, you can choose to export a sheet as PDF. Can that be triggered using API?

2,106 Views
Employee
Employee

Roy,

I just fixed the buttons. Csv, jpg and pdf should be fine now

Thnx

Yianni

2,106 Views
Partner
Partner

Hello Yianni,

I have a mashup with angularJS.

Can I use this feature with this kind of code ?

cda.controller( "ranking", ['$scope', function ( $scope ) {

     if ( !app ) {

     app = getQlikApp();

     }

     app.getObject('QVS101','21949850-064c-488f-ae41-c6000175a01f');     // my table object

    

     // When I click on the export data button I want to download the image of QVS101

     $scope.exportdata = function () {           

           

          // What should I write here ?

     });

}

Thanks,

Paul

0 Likes
2,106 Views
Partner
Partner

You should do something like this Paul

app.getObject('QVS101','21949850-064c-488f-ae41-c6000175a01f').then(function (model){

  // When I click on the export data button I want to download the image of QVS101

  $scope.exportdata = function () {     

      // What should I write here ?

      model.exportData().then(function(reply){

           windows.open('https://YOUR_SERVER/PREFIX' + reply.qUrl) // opens new window that downloads excel file

      });

  };

});

For image and PDF you can do like this

app.visualization.get('21949850-064c-488f-ae41-c6000175a01f').then(function(vis){

  vis.show("QVS101"); // to show the object on screen

  $scope.exportData = function () {

     vis.exportImg({ imageType: 'png', height: 200, width: 300 }).then(function(reply){

          console.log(reply); // the url for image

      });

   };

});

0 Likes
2,106 Views
Employee
Employee

I believe it should be something like

const qViz = null;

const options = { format: 'CSV_T', state: 'P' };

app.getObject('QVS101','21949850-064c-488f-ae41-c6000175a01f').then( ( viz ) => { qViz = viz; } )


$scope.exportdata = function () {

  qViz.exportData( options )

}

0 Likes
2,106 Views
Partner
Partner

Thank you Yiainni,

I haven't error with this code :

var qViz = null;               

        const options = { format: 'CSV_T', state: 'P' };

       

        app.getObject('QVS101','21949850-064c-488f-ae41-c6000175a01f').then((viz) => {

            qViz = viz;

            console.log('ok')

        }, (raison) => {

            console.log('ko')

        });

               

        $scope.exportdata = function () {

            qViz.exportData( options );

            console.log('ok');

        }

The problem is that nothing is exported (nothing in temp content).

I work on Qlik Sense Desktop.

Thanks

Paul

0 Likes
2,106 Views
Partner
Partner

To get errors if any you can do like this

var qViz = null;              

const options = { format: 'CSV_T', state: 'P' };

app.getObject('QVS101','21949850-064c-488f-ae41-c6000175a01f').then((viz) => {

    qViz = viz;

    console.log(qViz); // check so it is not undifined

});

$scope.exportdata = function () {

    qViz.exportData( options ).then(function(reply){

        console.log(reply); // working data

    })

    .catch(function(e) {

        console.log(e); // "error!"

    });

}

0 Likes
2,106 Views
Partner
Partner

Hello Roy,

Thank for your help !

I catch this error :


Error: Invalid method parameter(s)

    at t.J (4.b1640e38a27383e10f53.js:8)

    at l (require.js:18)

    at require.js:18

    at f.$digest (require.js:18)

    at require.js:18

    at p (require.js:18)

    at require.js:18

Console.log(qViz) return this :

  1. {_events: {…}, _maxListeners: undefined, setMaxListeners: ƒ, emit: ƒ, addListener: ƒ, …}
    1. Cancelled: n {observers: Array(1), receiver: {…}}
    2. Closed: n {observers: Array(2), receiver: {…}}
    3. Closing: n {observers: Array(0), receiver: {…}}
    4. Invalidated: n {observers: Array(8), receiver: {…}}
    5. Promise: ƒ E(e)
    6. Validated: n {observers: Array(0), receiver: {…}}
    7. Validating: n {observers: Array(0), receiver: {…}}
    8. addListener: ƒ (n,a)
    9. app: {_events: {…}, _maxListeners: undefined, setMaxListeners: ƒ, emit: ƒ, addListener: ƒ, …}
    10. close: ƒ ()
    11. emit: ƒ (e)
    12. enigmaModel: {_events: {…}, _maxListeners: undefined, setMaxListeners: ƒ, emit: ƒ, addListener: ƒ, …}
    13. genericType: "masterobject"
    14. handle: 18
    15. id: "21949850-064c-488f-ae41-c6000175a01f"
    16. layout: {qInfo: {…}, qMeta: {…}, qSelectionInfo: {…}, qHyperCube: {…}, showTitles: false, …}
    17. listeners: ƒ (e)
    18. migrate: {properties: ƒ, snapshot: ƒ}
    19. needCacheProperties: true
    20. notification: ƒ e(t)
    21. on: ƒ (n,a)
    22. once: ƒ (e,n)
    23. ongoingRequests: {}
    24. properties: {}
    25. removeAllListeners: ƒ (e)
    26. removeListener: ƒ (e,n)
    27. session: t {apis: e, config: {…}, intercept: t, rpc: t, suspendResume: t, …}
    28. setMaxListeners: ƒ (e)
    29. state: 1
    30. type: "GenericObject"
    31. _events: {changed: ƒ, closed: Array(3)}
    32. _maxListeners: undefined
    33. _properties: {}
    34. isCancelled: (...)
    35. isClosed: (...)
    36. isClosing: (...)
    37. isInvalid: (...)
    38. isValid: (...)
    39. isValidating: (...)
    40. get isCancelled: ƒ t()
    41. get isClosed: ƒ t()
    42. get isClosing: ƒ t()
    43. get isInvalid: ƒ t()
    44. get isValid: ƒ t()
    45. get isValidating: ƒ t()
    46. __proto__: Object

Paul

0 Likes
2,106 Views
Partner
Partner

Seems that the options parameter is wrong. Try to remove the options object in exportData(options). The default exportData() without parameters will export an Excel file.

0 Likes
2,106 Views
Partner
Partner

Hello Roy,

It's Ok without options

Here is the full code :

cda.controller( "ranking", ['$scope' , '$window', function ( $scope , $window ) {

if ( !app ) {

app = getQlikApp();

}


var qViz = null;             

var options = {download:true};


app.getObject('QVS101','21949850-064c-488f-ae41-c6000175a01f').then((viz) => {

qViz = viz;

console.log(qViz); // check so it is not undifined

});


$scope.exportdata = function () {

     qViz.exportData().then(function(reply){

     $window.open(reply.qUrl) // opens new window that downloads excel file

     console.log(reply); // working data

     })

       

     .catch(function(e) {

          console.log(e); // "error!"

     });

}

}] );

Thank you for your help !

Paul

2,106 Views
Partner
Partner

I'll add another problem with exportImg(). (We are using anonymous login on a virtual proxy.)

My code:

                    vis.exportImg(settings).then(function (url) {

                        console.log('Image download link: ', url);

                        window.open(url);

                    });

The url reports:

                    The requested resource cannot be found.

https://qlik-qap01.local.company.com/qlikpublic/tempcontent/89332cf1-2f02-4857-bc47-fbc5d2a1e633/e5b...

Looking at C:\ProgramData\Qlik\Sense\Repository\TempContent, I find both the folder ('89332cf1-2f02-4857-bc47-fbc5d2a1e633') and the file ('e5bb2962bbc640ecb93dd2d11589faa0.png').

The exportData() creates folders and urls the in the same place, and download works well.

Log files

Repository\Trace\QLIK-QAP01_System_Repository.txt reports:

INFO qlik-qap01 System.Repository.Repository.Communication.StaticContent.StaticContentRequestHandler Request failed: file not found /tempcontent/89332cf1-2f02-4857-bc47-fbc5d2a1e633/e5bb2962bbc640ecb93dd2d11589faa0.png

While Repository\Trace\QLIK-QAP01_Audit_Repository.txt reports:

INFO qlik-qap01 Audit.Repository.Repository.Core.Resource.TempContentResource Temporary content with path '/tempcontent/89332cf1-2f02-4857-bc47-fbc5d2a1e633/e5bb2962bbc640ecb93dd2d11589faa0.png' and data location 'C:\ProgramData\Qlik\Sense\Repository\TempContent\89332cf1-2f02-4857-bc47-fbc5d2a1e633\e5bb2962bbc640ecb93dd2d11589faa0.png' was created. ServeOnce = False, ExpirationDate = 10/10/2018 16:48:56 Add NONE anonymousXXXXXXXX-XXXX-XXXXXXXXXXXX

and similar when creating the XLSX file:

INFO qlik-qap01 Audit.Repository.Repository.Core.Resource.TempContentResource Temporary content with path '/tempcontent/6dcc9e5a-ccbe-4b90-863e-a8b3cca7937a/2f3da554-7752-457b-8434-dd6036e79c4d.xlsx' and data location 'C:\ProgramData\Qlik\Sense\Repository\TempContent\6dcc9e5a-ccbe-4b90-863e-a8b3cca7937a\2f3da554-7752-457b-8434-dd6036e79c4d.xlsx' was created. ServeOnce = False, ExpirationDate = 10/10/2018 17:04:55 Add NONE anonymousXXXXXXXX-XXXX-XXXXXXXXXXXX

Anyone got exportImg() working?

Are you using virtual proxies? Or anonymous login?

Cheers,

Vegard

0 Likes
2,106 Views
Partner
Partner

Actually, the documentation for exportImg() is wrong about the imageType. The settings should contain { format: 'png' }, but default is png, so it works.

0 Likes
2,106 Views
Employee
Employee

Hello Veggard,

Here it is working but I need to setup the certs properly. Will fix that this week

https://webapps.qlik.com/qdt-components/react/index.html?&_ga=2.226333010.975571039.1539169738-96304...

Check your security rules in the Qmc for "ExportAppData" and "OwnerAnonymousTempContent"

You may need to create another rule that gives access to the anonymous users to read the TempContent_* by a condition like "((user.name="*"))"

0 Likes
2,106 Views
Partner
Partner

Thank you,Yianni, for swift respons!

I have not looked into the OwnerAnonymousTempContent security rule.  But I have created a copy of the ExportAppData for the stream we use.


But does the OwnerAnonymousTempContent treat anonymous access differently, depending on whether it is an Excel file, or a PNG file? Because the anonymous user can easily download the Excel book.

0 Likes
2,106 Views
Partner
Partner

My OwnerAnonymousTempContent is

user.IsAnonymous() and resource.anonymousOwnerUserId = user.userId

Which makes sense to me: The content is accessible for anonymous users, but only for the content owned by that particular anonymous user.

I don't understand why this should not work for PNG files, when it works for Excel-files. 😕

0 Likes
2,106 Views
Employee
Employee

OK qdt-components with the new export features is working now

https://webapps.qlik.com/qdt-components/react/index.html#/embed-object

0 Likes
2,106 Views
Partner
Partner

jvs

Can you tell me if the export image call will also be available in the .NET SDK. I have checked last week, could not find it.

0 Likes
2,106 Views

I have tried this and get the same result.

If i call model.exportData() i get an excel file with the possible values of the table but I am trying to give users the option to download either all values or the possible values.

So according to the documentation i neeed to pass options = { 'state' : 'A' }

or options = { 'state' : 'P' } for all or possible values respectively.


I have tried both and get the following error:


portal.js:25 Qlik error Error: Invalid method parameter(s)

    at t.J (4.b1640e38a27383e10f53.js:8)

    at l (require.js:18)

    at require.js:18

    at f.$digest (require.js:18)

    at require.js:18

    at p (require.js:18)

    at require.js:18

portal.js:27 [Error: Invalid method parameter(s)

    at t.J (https://entademoqap.entadatacenter.com/eton-travel/re…]

I even tried with the adding format to the options object but get the same result:

i.e. options = { format: 'OOXML', state: 'A' } ....etc.

But i get the same result.

Is this a bug?

I have also tried creating a new table from the object model and exporting this as was indicated as the method for earlier verisons of Qlik Sense in various posts but this didn't work either.

Does anyone know what the solution to this is? Or should i be speaking to Qlik Support?

0 Likes
2,106 Views
Partner
Partner

 @Yianni_Ververis Please answer my question: 

Can you tell me if the export image call will also be available in the .NET SDK. I have checked last week, could not find it.

 

I have been waiting for this possibility for  a while. It should already be possible but is not refferenced. So please help me out.

0 Likes
2,037 Views
Employee
Employee

@b_knuever No idea. I will look into it and let you know.

2,033 Views
Employee
Employee

I encourage everyone, if you have not done already, to join qlik-branch.slack.com.

0 Likes
2,026 Views
Partner
Partner

@Yianni_Ververis Did you find any info on this?

0 Likes
1,897 Views