<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: export featuretable to csv exports only one field and objectid in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/export-featuretable-to-csv-exports-only-one-field/m-p/1201608#M78252</link>
    <description>&lt;P&gt;That's an old sample. I would try a couple of things.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Set outFields of layer to ["*"]&lt;/LI&gt;&lt;LI&gt;Or set outFields of query to ["*"]&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I suspect the fields are not in the query results, so you need to ask for them all.&lt;/P&gt;</description>
    <pubDate>Wed, 10 Aug 2022 21:27:32 GMT</pubDate>
    <dc:creator>ReneRubalcava</dc:creator>
    <dc:date>2022-08-10T21:27:32Z</dc:date>
    <item>
      <title>export featuretable to csv exports only one field and objectid</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/export-featuretable-to-csv-exports-only-one-field/m-p/1201600#M78251</link>
      <description>&lt;P&gt;I use Rene's example posted at: &lt;A href="https://codepen.io/odoe/pen/rqXqVw?editors=0010" target="_blank"&gt;https://codepen.io/odoe/pen/rqXqVw?editors=0010&lt;/A&gt;&lt;/P&gt;&lt;P&gt;to export featuretable to csv but it produces a csv file with 2 fields including the objectid.&lt;/P&gt;&lt;P&gt;I first selected the features by the geometry.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="LefterisKoumis_0-1660165724407.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/48324iB89F5DEDA570F49D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="LefterisKoumis_0-1660165724407.png" alt="LefterisKoumis_0-1660165724407.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Then the feature table is updated to show selected features.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="LefterisKoumis_2-1660165866696.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/48326i6D4079DEF3EBC59C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="LefterisKoumis_2-1660165866696.png" alt="LefterisKoumis_2-1660165866696.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then clicked on the export button to create the csv file but only one field&amp;nbsp; but records span across multiple fields!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="LefterisKoumis_3-1660165931818.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/48327i473E244802E2EB95/image-size/medium?v=v2&amp;amp;px=400" role="button" title="LefterisKoumis_3-1660165931818.png" alt="LefterisKoumis_3-1660165931818.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;As Rene's example shows, first declare the variable&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;let resultFeatures&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;get the selected features.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt; featureLayerView
            .queryFeatures(query)
            .then((results) =&amp;gt; {
              const graphics = results.features;
              resultFeatures = graphics;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;THen, attach code to the export button:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;view.ui.add("btn-export", "top-left");
      const btn = document.getElementById("btn-export");
      btn.addEventListener("click", () =&amp;gt; {

        if (resultFeatures.length) {          
          // export to csv
          const attrs = resultFeatures.map(a =&amp;gt; a.attributes);
          console.log(attrs)
          const headers = {};
          const entry = attrs[0];
          for (let key in entry) {
            if (entry.hasOwnProperty(key)) {
              headers[key] = key;
            }
          }
          exportCSVFile(headers, attrs, "export");
        }
      });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The issue by now is exposed because one field is passed on to the CSV. Why?&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2022 21:19:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/export-featuretable-to-csv-exports-only-one-field/m-p/1201600#M78251</guid>
      <dc:creator>LefterisKoumis</dc:creator>
      <dc:date>2022-08-10T21:19:43Z</dc:date>
    </item>
    <item>
      <title>Re: export featuretable to csv exports only one field and objectid</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/export-featuretable-to-csv-exports-only-one-field/m-p/1201608#M78252</link>
      <description>&lt;P&gt;That's an old sample. I would try a couple of things.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Set outFields of layer to ["*"]&lt;/LI&gt;&lt;LI&gt;Or set outFields of query to ["*"]&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I suspect the fields are not in the query results, so you need to ask for them all.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2022 21:27:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/export-featuretable-to-csv-exports-only-one-field/m-p/1201608#M78252</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2022-08-10T21:27:32Z</dc:date>
    </item>
    <item>
      <title>Re: export featuretable to csv exports only one field and objectid</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/export-featuretable-to-csv-exports-only-one-field/m-p/1201630#M78254</link>
      <description>&lt;P&gt;Thank you. I already had the query to outFields=["*"] but not the layer. Apparently, by not using the same for the layer it does not by default use all fields even though the featuretable displays all fields.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2022 22:03:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/export-featuretable-to-csv-exports-only-one-field/m-p/1201630#M78254</guid>
      <dc:creator>LefterisKoumis</dc:creator>
      <dc:date>2022-08-10T22:03:06Z</dc:date>
    </item>
  </channel>
</rss>

