Can't export Query result to CSV

288
5
Jump to solution
06-18-2019 12:22 AM
simoxu
by MVP Regular Contributor
MVP Regular Contributor

I tried this in both WAB Portal version and Developer Edit, and he result seems the same. Here is what's shown in the Chrome console:

Further investigation reveals that the cause is the projection of the query result (wkid: 4326 in my case) is not the same as the map projection (wkid:102100).

In the code (exportToCSV function in _FeatureTable.js), it says:

            var isSameProjection = this.layer.fullExtent.spatialReference.equals(
this.map.extent.spatialReference);

var hasArcadeExpressionFields = this._hasArcadeExpressionFields();

// if the output layer's spatial reference is the same as map's, which means
// a spatial reference conversion to make output data (X, Y fileds) consistent with
//layer's original projection system is NOT needed. then we can use data from client side.
// if they are different, then it needs to send a query request to
// server side (handle by "_getExportDataFromServer" method in jimu/CSVUtils.js)
// to get the data with correct spatial reference
if(isSameProjection) {
var rows = array.map(
this._getTableSelectedIds(),
lang.hitch(this, function(id) {
for (var i = 0, len = datas.length; i < len; i++) {
if (datas[i] && datas[i][oid] === id) {
return datas[i];
}
}
return {};
})
);
var _selectedData = rows || [];// get selected data
// if table were in selection mode and no records were selected, we push an
// empty object to _selectedData, for the following logic compatible.
if(_selectedData.length === 0 && this.isSelectionMode()){
_selectedData.push({});
}

_exportData = _selectedData;

if(_selectedData.length === 0 && this.grid.store instanceof Memory){
_exportData = lang.clone(this.grid.store.data);
}

if(_exportData.length){
this._appendXY(_exportData);
}
}

If I force isSameProject to equal to "true", it will work.

But,  will that have any side-effects to other parts of my applicaiton? is it a Query widget bug or AttributeTable widget bug? My data and my map are both in 102100 projection, I have no idea where the 4326 spatial reference comes from.

0 Kudos
1 Solution

Accepted Solutions
simoxu
by MVP Regular Contributor
MVP Regular Contributor

Bug confirmed.

BUG-000123249 - Exporting an attribute table to a CSV from a Query layer created via the Query Widget in Web App Builder fails, returning no error message.

View solution in original post

0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Simo,

   So are your creating the layer that you are exporting to csv from a FeatureLayer using a featureCollection? If so then if you do not specify the spatialrefernce of the layer then the default is 4326.

simoxu
by MVP Regular Contributor
MVP Regular Contributor

Hi Robert

I am not creating the temp layers manually, it is created by the Query widget when a query is executed. After the layer is created, it will be shown in the AttributeTable widget as well as in the LayerList widget.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Then a call to esri tech support is required.

simoxu
by MVP Regular Contributor
MVP Regular Contributor

Yep. I've contacted ESRI Australia. I suspect this is a bug in Attribute Table Widget because I can export the result to CSV in the Query Widget. I'll update this post when ESRI confirms this.

Thanks.

0 Kudos
simoxu
by MVP Regular Contributor
MVP Regular Contributor

Bug confirmed.

BUG-000123249 - Exporting an attribute table to a CSV from a Query layer created via the Query Widget in Web App Builder fails, returning no error message.

View solution in original post

0 Kudos