Web App Builder - How to limit fields in "export to CSV" option in query widget?

4669
16
Jump to solution
05-31-2017 09:24 AM
KyleSchwizer
New Contributor III

I am trying to limit the fields exported in the "export to CSV" option for the query widget. I would like to just limit the field exported to the same fields that are within our popups for our parcels.  I know i might have to dive into the code in the CSV.Utils.js for the application. Any direction or help to lead me to a work around would be great. I am working with Web App Builder for Developers 2.4.

0 Kudos
16 Replies
RobertScheitlin__GISP
MVP Emeritus

Kyle,

   In the eSearch you would use "Search Results: Whatever the name of the layer is in the LayerList widget"

0 Kudos
KyleSchwizer
New Contributor III
_getFeatureSet: function(){
        var layer = this.currentSearchLayer;
        var featureSet = new FeatureSet();
        if (layer.name==="Search Results: Parcel"){
          layer.fields = ["PIN];
        } else if (layer.name==="Address _Query Result") {
          layer.fields = ["ADDRESS"];
        }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

So I have tried to make those adjustments in the Widget.js for the eSearch widget. Upon exporting the data as a CSV, it seems to be carrying over the result formatting that is specified in the app configuration. I am a little confused as to how the currentSearchLayer is create and or what exactly that returns.  Is there something else i should be specifiying?

thanks,

Kyle

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Kyle,

   The search results layer is a client side FeatureLayer from a FeatureCollection and thus the attributes will be formatted using the eSearch widget settings.

0 Kudos
KymMcDonagh
New Contributor II

Hi

I am also trying to limit the number of fields that can be viewed in the csv results from query widget.

At present it shows everything. I want to limit this right down to 4 fields. How do I go about doing this

Robert you mentioned making changes to this line

"In the SingleQueryResult.js file find this line

featureSet.fields = lang.clone(layer.fields);

This is where the fields that are exported are specified. You could modify the available field here before it is passed to the ExportToCSV.js"

I am not exactly sure how to proceed. in the brackets should I be replacing text layer.fields with the titles of the fields I want included?

Thanks

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Kym,

   You would filter the fields array before you pass it to the lang.clone.

var myFlds = ["x","y","z"];
var fFlds = array.filter(layer.fields, lang.hitch(this, function(fldInfo) {
   return  myFlds.indexOf(fldInfo.name) > 0;
;}));
featureSet.fields = lang.clone(fFlds);
0 Kudos
KymMcDonagh
New Contributor II

Thanks for the reply Robert. I will try this out.  Cheers

0 Kudos
LisaT
by
Occasional Contributor III

I have a question that seems very related to these questions, but concerns getting data from related records.  I would like to print my related table with information in it on the parent featureclass. Is there a way to alter this line:

layer.fields = ["PIN"];

To something like ["relatedTbl.PIN"] to get related table information?  I have guys in the field collecting with Collector (where I can't customize the data that goes into the fields).  I can't find a way to relate the data when I export into csv once the guys get back to their desks.  Just printing the csv table of the inspection doesn't indicate what it was an inspection for.  Any ideas?

0 Kudos