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

1540
15
Jump to solution
05-31-2017 09:24 AM
Highlighted
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.

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
MVP Esteemed Contributor

Kyle,

   The layer.id will not be 5 it will be something like "graphicsLayer4". I would use the layer.name instead:

if (layer.name === "Owner Parcels _Query Result"){

View solution in original post

15 Replies
Highlighted
MVP Esteemed Contributor

Kyle,

   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

Highlighted
New Contributor III

Robert,

So I have been able to get result that i am looking for, however it is being applied to all the layers within my query widget.  I have both parcels and address points being used in my query widget  When i go to export out address points results as a CSV the results will only list the "PIN" field. Which in my address point data is not a valid field.

        layer.fields = ["PIN"]
        featureSet.fields = lang.clone(layer.fields);

Is there a way that i can call the Layer's popup configuration from the web map as the fields that should be exported?  So instead of doing the above code, limit the featureSet.fields to the web map popup that is specified in the query configuration dialogue box? 

Reply
0 Kudos
Highlighted
MVP Esteemed Contributor

Kyle,

   What you are asking for would be difficult. The easier way would be to check which layer id you are working with and apply the code change based on the proper layer or not.

Reply
0 Kudos
Highlighted
New Contributor III

Robert,

This sounds like a better way of accomplishing what I would like to do. I have the if else statement created but I am having trouble getting the layerID from the layer variable. Should i create another var that gets the layer info from the query.resultLayer? It is probably really simply what i am tyring to do but i am somewhat new to custom coding.

  var layer = this.currentAttrs.query.resultLayer;
        var featureSet = new FeatureSet();
        if (layer.id===5){
          layer.fields = ["PIN"];
        } else if (layer.id===1) {
          layer.fields = ["ADDRESS"];
        }
        ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
Reply
0 Kudos
Highlighted
MVP Esteemed Contributor

Kyle,

   The layer.id will not be 5 it will be something like "graphicsLayer4". I would use the layer.name instead:

if (layer.name === "Owner Parcels _Query Result"){

View solution in original post

Highlighted
New Contributor III

Robert,

It worked perfectly! Now just have to go in and add the fields i would like.  Thank you so much for sharing your wealth of knowledge.

_getFeatureSet: function() {
        var layer = this.currentAttrs.query.resultLayer;
        var featureSet = new FeatureSet();
        if (layer.name==="Parcel _Query Result"){
          layer.fields = ["PIN"];
        } else if (layer.name==="Address _Query Result") {
          layer.fields = ["ADDRESS"];
        }
Highlighted
MVP Esteemed Contributor

Great don't forget to mark this question as answered.

Reply
0 Kudos
Highlighted
New Contributor III

Robert,

If i wanted to accomplish the same task in your Enhanced Search widget, how would the layer.name string be formatted? It was easy to figure out how the layer.name was formatted in the Query widget but with your Enhanced Search widget i am having a little bit more difficulty. 

Reply
0 Kudos
Highlighted
MVP Esteemed Contributor

Kyle,

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

Reply
0 Kudos