Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
balexbyrd
Contributor III
Contributor III

Qlik Sense 2.1 Engine API; ExportData to CSV

Need some help Qlik family! swr‌ Got me started but I need some help to bring this home.

Use case:

The user clicks a button and sends an object (a pre-constructed table with defined object ID) to a specific folder path on the server with a filename the user chooses.

Detail:

Using Qlik Sense 2.1 and solution can be an extension object or mashup.

Current Status:

Following the discussion here: Mashup Api - Exporting Qlik Sense Table to CSV

1. Starting a new Mashup 'Basic template with absolute positioning'

2. Drag my object in from 'Demo.qvf' with object ID of 'emURxRW'

3. Update the Demo.js file with Stefan Walther's code under app.getObject('QV01','emURxRW');

var qTable = qlik.table(this);

var $exportButton = $( document.createElement('button'));

$exportButton.html('Export');

$exportButton.bind('click', function (  ) {

     qTable.exportData({download: true});

     }

);

$element.append($exportButton);

4. Save and refresh

There's no button or ability to export to csv.

Secondly, I'd need the ability to manipulate the filename that's downloaded and the filepath.

Any help? Thank you in advance!

Other useful links for others in the same position:

yianni-ververis/Export-Table-to-Csv · GitHub

How to include "Export data" feature in a mashup

http://help.qlik.com/sense/2.0/en-US/developer/#../Subsystems/EngineAPI/Content/Classes/GenericObjec...

Leverage qsocks from within a mashup · GitHub

1 Solution

Accepted Solutions
balexbyrd
Contributor III
Contributor III
Author

Also see: Object to CSV/XML

However it will not pick up the file name on the server as mentioned above.

View solution in original post

10 Replies
Alexander_Thor
Employee
Employee

I'm not exactly sure what you are trying to do but this is an example on how to export a specific object model using the new Table API.

require( ["js/qlik", 'jquery'], function ( qlik, $ ) {

  var app = qlik.openApp('Executive Dashboard.qvf', config);

  var $exportButton = $( document.createElement('button')).text('Export').appendTo('body');

  var object = app.getObject('QV01','fzrxtjq');

  object.then(function(model) {

  

        var table = new qlik.table(model);

        $exportButton.bind('click', function() {

            table.exportData({download: true});

        })

  

  })

});

This will open the app Executive Dashboard.

Get the object fzrxtjq, a scatter plot, inject that chart to the page.

Then bind that objects model to an instance of the table api, then upon clicking the button export that table instance.

balexbyrd
Contributor III
Contributor III
Author

Thank you for your quick reply and your github has been a huge help for me. I should really post up more often as I figured out most of my issues right after.

I created input boxes to be used as the filename when the user pushes the 'Order Sample' button. Naming the file works beautifully when I'm using my desktop however when I uploaded everything to the server, it no longer names the file.

Even when I use a string like 'Test' for the filename in the exportData function it downloads the file to 'C:\ProgramData\Qlik\Sense\Repository\TempContent' using the hash name (I believe that's what it's called). Pictures below.

Preview

Preview.PNG

OrderForm.html

<!doctype html>

<html><head>

    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <title>Qlik Sense: Mashup</title>

    <meta charset="utf-8">

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">

    <meta name="HandheldFriendly" content="True">

    <meta name="MobileOptimized" content="320">

    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">

    <meta name="apple-mobile-web-app-capable" content="yes">

    <meta name="apple-mobile-web-app-status-bar-style" content="black">

    <meta http-equiv="cleartype" content="on">

    <!--Add host to these 3 links if the mashup is on another webserver than qlik sense static content-->

    <link rel="stylesheet" href="https://community.qlik.com/resources/autogenerated/qlikui.css">

    <link rel="stylesheet" href="https://community.qlik.com/resources/assets/client/client.css" media="all">

    <script src="/resources/assets/external/requirejs/require.js"></script>

    <script src="OrderForm.js"></script>

    <style>

        article.qvobject

        {

            position:absolute;

            overflow: hidden;

            padding: 10px;

        }

    </style>

</head>

<body style="overflow:auto">

<form style="position: absolute; top: 10px; left: 20px;">

  User Name:<br>

  <input type="text" name="UserName">

  <br><br>

  Order Name:<br>

  <input type="text" name="OrderName">

  <br>

</form>

<button id="cmdExport" onsubmit="return validateForm()" style="display:none; position: absolute; top: 110px; left: 20px; width: 100px; height: 20px">

   Order Sample

</button>

<div id="QV01" style="position: absolute; top: 10px; left: 180px; width: 900px; height: 60px;" class="qvobject"></div>

</body></html>

OrderForm.js

/*global require, alert*/

/*

*

* @owner Enter you name here (xxx)

*/

/*

*    Fill in host and port for Qlik engine

*/

var config = {

  host: window.location.hostname,

  prefix: "/",

  port: window.location.port,

  isSecure: window.location.protocol === "https:"

};

require.config( {

  baseUrl: ( config.isSecure ? "https://" : "http://" ) + config.host + (config.port ? ":" + config.port: "") + config.prefix + "resources"

} );

require( ["js/qlik"], function ( qlik ) {

  qlik.setOnError( function ( error ) {

  alert( error.message );

  } );

  //callbacks -- inserted here --

  //open apps -- inserted here --

  var app = qlik.openApp('13cd798a-65e7-4800-b1f1-09bd3cdf586f', config);

  //get objects -- inserted here --

  app.getObject('QV01','17386bdd-fe1b-4ef0-bad6-8df6044fe08d').then( function( vizModel ) {

      // Prevent clicking on the button too early

      $('#cmdExport').show();

      $('#cmdExport').on('click', function() {

  if (document.getElementsByName("UserName")[0].value == "" || document.getElementsByName("OrderName")[0].value == "" ){

   alert("You must fill out both inputs before submiting an order");

   return false;

  }

  var username = document.getElementsByName("UserName")[0].value;

  var orderID = document.getElementsByName("OrderName")[0].value;

  d = new Date();

  var dstring = d.valueOf(); // number of milliseconds since midnight January 1, 1970 UTC.

  var ordername = username+'_'+orderID+'_'+dstring;

  vizModel.exportData('CSV_C','/qHyperCubeDef','Test','A').then(function( reply ) {

    //console.log('qUrl', reply);

            alert("Success!");

   //window.open(reply.result.qUrl);  // Will download CSV to browser window as well as Export folder

         });

      })

   });

} );


You'll see the vizModel.exportData file name to be 'Test' and the file doesn't download as 'Test'


Export.PNG


So it works great on the desktop and doesn't work at all on the server. If you console.log(ordername) you'll see the values show up in the browser but it does not get passed to the folder/filename. Any help?

balexbyrd
Contributor III
Contributor III
Author

Also see: Object to CSV/XML

However it will not pick up the file name on the server as mentioned above.

Anonymous
Not applicable

We're doing an implementation on a client with Qlik Sense, and they need to generate a report based on a table. The object is a simple table and must be exported based on selections (filters) given by generating export data to Excel, said that the data has been truncated, and the table is not exported with the full data off an alert at the time of export where it says that the data has been truncated

It has been consulted in the community and informs an extension that works and exports all the records in csv, but is not functional when you select (filter) so this solution is not feasible performed.

Also on the Help of Qlik Sense on the web talking about a method called ExportData but I have not managed correctly set or not if that is the solution.

Your cooperation in this area is essential for the complete customer information when generating reports from Qlik Sense.

Thanks...

brijeshvma
Partner - Creator
Partner - Creator

Hi Alex,

Ur Given Link for Object to CSV/XML  is not working. do you have any update link for the same

balexbyrd
Contributor III
Contributor III
Author

Here we are - hope this helps. The API is still not perfect. Please see the documentation on limitations.

There are some other export extensions in my github repo. Feel free to take a look.

GitHub - balexbyrd/sense-Object2Excel: Automatically export any Qlik Sense object to excel, hidden o...

Limitations

https://help.qlik.com/en-US/sense-developer/2.1/Subsystems/EngineAPI/Content/Classes/GenericObjectCl...

Anonymous
Not applicable

Hi Alexander, I used your method to create a button in Qlik sense mashup page to export data from Qlik sense table object. It works well in my local Qlik sense desktop, and it also works in Qlik sense server when I keep logging in Qlik sense server.

However, after I published the mashup at Qlik sense server with anonymous access, the "export" does not work any more in Qlik sense mashup page.

Could you please give any suggestion?

Thanks!

Anonymous
Not applicable

The link is not available any more.

Could the method allow to export data from Qlik sense mashup for Qlik sense anonymous users?

Qlik sense exportData and Table API only work for Qlik sense authorized users, but do not work for Qlik sense anonymous users.

However, the published Qlik sense mashup is public access WITHOUT Qlik sense user_id and password, how to make it to export data from Qlik sense mashup for Qlik sense anonymous user?

Thanks!

Anonymous
Not applicable

Hi Alex,  is the method able to export data from Qlik sense mashup for Qlik sense anonymous users?

Qlik sense exportData and Table API only work for Qlik sense authorized users, but do not work for Qlik sense anonymous users.

However, the published Qlik sense mashup is public access WITHOUT Qlik sense user_id and password, how to make it to export data from Qlik sense mashup for Qlik sense anonymous user?

Thanks!