Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
Yianni_Ververis
Employee
Employee

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

32 Comments
paulcalvet
Partner - Specialist
Partner - Specialist

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
5,823 Views
royal_87
Partner - Contributor III
Partner - Contributor III

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
5,823 Views
Yianni_Ververis
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
5,819 Views
paulcalvet
Partner - Specialist
Partner - Specialist

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
5,819 Views
royal_87
Partner - Contributor III
Partner - Contributor III

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
5,819 Views
paulcalvet
Partner - Specialist
Partner - Specialist

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
5,819 Views
royal_87
Partner - Contributor III
Partner - Contributor III

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
5,819 Views
paulcalvet
Partner - Specialist
Partner - Specialist

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

5,819 Views
vegard_bakke
Partner - Creator III
Partner - Creator III

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
5,795 Views
vegard_bakke
Partner - Creator III
Partner - Creator III

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
5,795 Views