Export to CSV from a featureLayer with no url

Discussion created by lkoumis on Sep 19, 2018

Just wanted to share this in case someone else comes across this issue.


This applies when you create a new featurelayer on the fly based on the results of a query or an analysis tool.


When you want to export the attributes of the new FL, even though the option to export to CSV is on, you will not be able to export because of the absence of the featurelayer.url. 

To resolve this issue go to the jimu.js/CSVUtils.js and add the lines 15-18. After you add these lines, you will be able to export the FL attributes.



exports.exportCSVFromFeatureLayer = function(filename, layer, options) {
      options = options || {};
      var exportOptions = {
        datas: options.datas,
        objectIds: options.objectIds,
        fromClient: options.fromClient,
        withGeometry: options.withGeometry,
        outFields: options.outFields,
        filterExpression : options.filterExpression,
        outSpatialReference: options.outSpatialReference
       if(layer.url === null){
            exportOptions.fromClient = true;
            exportOptions.withGeometry =true;
      return exports._getExportData(layer, exportOptions).then(function(result) {
        var formattedOptions = {
          formatNumber: options.formatNumber,
          formatDate: options.formatDate,
          formatCodedValue: options.formatCodedValue,
          popupInfo: options.popupInfo
        return exports._formattedData(layer, result, formattedOptions)
          .then(function(formattedResult) {
            return exports.exportCSV(filename, formattedResult.datas, formattedResult.columns);