<?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 Extract field of featurelayer as object in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/extract-field-of-featurelayer-as-object/m-p/1015160#M71329</link>
    <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;How do we extract all fields of featurelayer as an object? I tried this but didn't worked:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;fieldslist&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;=&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;featureLayer&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;fields&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;document&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;getElementById&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;"List"&lt;/SPAN&gt;&lt;SPAN&gt;).&lt;/SPAN&gt;&lt;SPAN&gt;innerHTML&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;=&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;fieldslist&lt;/SPAN&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;].&lt;/SPAN&gt;&lt;SPAN&gt;NLFID&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I require this to perform computations only using some of the fields.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Thank you in advance!&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Fri, 08 Jan 2021 18:56:51 GMT</pubDate>
    <dc:creator>RabinSubedi</dc:creator>
    <dc:date>2021-01-08T18:56:51Z</dc:date>
    <item>
      <title>Extract field of featurelayer as object</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/extract-field-of-featurelayer-as-object/m-p/1015160#M71329</link>
      <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;How do we extract all fields of featurelayer as an object? I tried this but didn't worked:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;fieldslist&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;=&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;featureLayer&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;fields&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;document&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;getElementById&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;"List"&lt;/SPAN&gt;&lt;SPAN&gt;).&lt;/SPAN&gt;&lt;SPAN&gt;innerHTML&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;=&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;fieldslist&lt;/SPAN&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;].&lt;/SPAN&gt;&lt;SPAN&gt;NLFID&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I require this to perform computations only using some of the fields.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Thank you in advance!&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 08 Jan 2021 18:56:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/extract-field-of-featurelayer-as-object/m-p/1015160#M71329</guid>
      <dc:creator>RabinSubedi</dc:creator>
      <dc:date>2021-01-08T18:56:51Z</dc:date>
    </item>
    <item>
      <title>Re: Extract field of featurelayer as object</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/extract-field-of-featurelayer-as-object/m-p/1015185#M71334</link>
      <description>&lt;P&gt;The &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#fields" target="_self"&gt;fields property of FeatureLayer&lt;/A&gt; will return an array of field objects, each having a field's properties. I found this only to be available once the FeatureLayer's&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#event-layerview-create" target="_self"&gt;layerview-create event&lt;/A&gt; has fired.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;featureLayer.on("layerview-create", function(event){
  console.log(featureLayer.fields);
  console.log(featureLayer.getField("NLFID"));
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2021 19:48:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/extract-field-of-featurelayer-as-object/m-p/1015185#M71334</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-01-08T19:48:06Z</dc:date>
    </item>
    <item>
      <title>Re: Extract field of featurelayer as object</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/extract-field-of-featurelayer-as-object/m-p/1015268#M71338</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/191789"&gt;@BlakeTerhune&lt;/a&gt;&amp;nbsp;for your reply. I used layerview-create event and tried to test the result by printing NLFID value of the first feature, but it didn't work. Can you please take a look at it? Does the 'fieldsList' variable contain all the fields (let's say the whole attribute table)?&lt;/P&gt;&lt;P&gt;Thanks much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;meta charset="utf-8"&amp;gt;
  &amp;lt;meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no"&amp;gt;
  &amp;lt;title&amp;gt;High Injury Network&amp;lt;/title&amp;gt;
  &amp;lt;style&amp;gt;
    html, body, #viewDiv {
      padding: 0;
      margin: 0;
      height: 50%;
      width: 100%;
    }
  &amp;lt;/style&amp;gt;
  
    &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.18/esri/themes/light/main.css"&amp;gt;
  &amp;lt;script src="https://js.arcgis.com/4.18/"&amp;gt;&amp;lt;/script&amp;gt;
  
  &amp;lt;script&amp;gt;  

    require([
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/FeatureLayer",
        "esri/layers/GraphicsLayer",
        "esri/geometry/geometryEngine",
        "esri/Graphic"
      ], function (
        Map,
        MapView,
        FeatureLayer,
        GraphicsLayer,
        geometryEngine,
        Graphic
      ) {
        var Crashes = [1,2];
        var HINLayer = new FeatureLayer({
          url: "https://services1.arcgis.com/wb4Og4gH5mvzQAIV/arcgis/rest/services/HIN_Columbus/FeatureServer",
          outFields: ["*"],
          visible: true
        });

        var resultsLayer = new GraphicsLayer();

      var map = new Map({
        basemap: "topo-vector",
        layers: [HINLayer, resultsLayer]
      });

      var view = new MapView({
        container: "viewDiv",
        map: map,
        center: [-82.9, 39.99], // longitude, latitude
      zoom: 10
      });
      
HINLayer.on("layerview-create", function(event){
        var fieldsList= HINLayer.fields;
        document.getElementById("List").innerHTML = fieldsList[0].NLFID;
        
});
      
   var sortedList = Crashes.sort();
   var sortedString = sortedList.join("','");
   var whereClause = "VehCrashCo IN ('" + sortedString + "')";
   var query = HINLayer.createQuery();
          query.where = whereClause ;
         // query.outStatistics = [ sumCost];
          query.returnGeometry= true;
          
          return HINLayer.queryFeatures(query).then(function(results){
            
            resultsLayer.removeAll();
          
          var features = results.features.map(function (graphic) {
            graphic.symbol = {
              
              color: "darkorange"
            };
            
            return graphic;
          });
          resultsLayer.addMany(features);
          
          });

    });
&amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
  &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
  &amp;lt;div id="List"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2021 22:57:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/extract-field-of-featurelayer-as-object/m-p/1015268#M71338</guid>
      <dc:creator>RabinSubedi</dc:creator>
      <dc:date>2021-01-08T22:57:47Z</dc:date>
    </item>
    <item>
      <title>Re: Extract field of featurelayer as object</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/extract-field-of-featurelayer-as-object/m-p/1015273#M71339</link>
      <description>&lt;P&gt;Oh, you want field &lt;EM&gt;values&lt;/EM&gt;, not field &lt;EM&gt;names&lt;/EM&gt;? You'll have to &lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/featurelayer-query-basic/index.html" target="_self"&gt;query the FeatureLayer&lt;/A&gt; and then do something with the result. In your case, if you only want to display a single value from the first feature returned. Something like this maybe? And you don't need the layerview-create event listener for query.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;HINLayer.queryFeatures({
  start: 0,
  num: 1,
  returnGeometry: false,
  outFields: ["NLFID"],
})
.then(function(featureSet) {
  let listContent;
  if(featureSet.features.length &amp;gt; 0) {
    listContent = featureSet.features[0].attributes.NLFID;
  } else {
    listContent = "There are no records in HINLayer";
  }
  document.getElementById("List").textContent = listContent;
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2021 23:29:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/extract-field-of-featurelayer-as-object/m-p/1015273#M71339</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-01-08T23:29:25Z</dc:date>
    </item>
    <item>
      <title>Re: Extract field of featurelayer as object</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/extract-field-of-featurelayer-as-object/m-p/1015293#M71341</link>
      <description>&lt;P&gt;Actually, I need to do a tradeoff analysis with the data of this layer and present the resulting features in map and charts. I need to perform multiple queries and filtering according to my task requirement, which might be possible with ArcGIS JS API but I am not familiar with it, so it will take me a lot of time. I was hoping to extract the whole attribute table in the form of an object like this:&lt;/P&gt;&lt;P&gt;attributeData = [ { "OBJECTID": 1, "NLFID": "CFRACR00125**C", "SUM_c_segm": 6.0, "SUM_w_segm": 11.0, "STREET_NAM": "FRANK RD"},&lt;BR /&gt;{ "OBJECTID": 2, "NLFID": "CFRACR00114**C", "SUM_c_segm": 5.0, "SUM_w_segm": 6.0, "STREET_NAM": "COURTRIGHT RD"},&lt;BR /&gt;{ "OBJECTID": 3, "NLFID": "CFRACR00602**C", "SUM_c_segm": 5.0, "SUM_w_segm": 7.0, "STREET_NAM": "TOWN ST"}&lt;BR /&gt;...&lt;BR /&gt;...&lt;BR /&gt;...&lt;/P&gt;&lt;P&gt;}]&lt;/P&gt;&lt;P&gt;After the analysis, I plan to pass the array of OBJECTID of resulting features to the query to display them in the map. Is it possible to extract all data in this way?&lt;/P&gt;&lt;P&gt;I am sorry I couldn't make it clear earlier and I apologize for your trouble.&lt;/P&gt;&lt;P&gt;Thank You!&lt;/P&gt;</description>
      <pubDate>Sat, 09 Jan 2021 00:45:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/extract-field-of-featurelayer-as-object/m-p/1015293#M71341</guid>
      <dc:creator>RabinSubedi</dc:creator>
      <dc:date>2021-01-09T00:45:21Z</dc:date>
    </item>
    <item>
      <title>Re: Extract field of featurelayer as object</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/extract-field-of-featurelayer-as-object/m-p/1015294#M71342</link>
      <description>&lt;P&gt;Blake's response gets you almost there:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// LAYER QUERY //
const query = HIMLayer.createQuery();
query.set({
  where: "1=1",
  returnGeometry: false
});
// RETRIEVE ALL FEATURES FROM LAYER //
HINLayer.queryFeatures(query).then((featureSet) =&amp;gt; {
  // FEATURES THAT SATISFY THE ABOVE QUERY //
  const features = featureSet.features;
  // CREATE LIST OF ATTRIBUTES FROM THE FEATURES //
  const attributeData = features.map(feature =&amp;gt; {
    return feature.attributes;
  });
  // DO SOMETHING WITH LIST OF ATTRIBUTES //
  document.getElementById("List").textContent = attributeData;
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you're only interested in the OBJECTIDS, then check out the&amp;nbsp;&lt;SPAN&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#queryObjectIds" target="_self"&gt;queryObjectIds&lt;/A&gt;() method.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Jan 2021 00:58:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/extract-field-of-featurelayer-as-object/m-p/1015294#M71342</guid>
      <dc:creator>JohnGrayson</dc:creator>
      <dc:date>2021-01-09T00:58:10Z</dc:date>
    </item>
    <item>
      <title>Re: Extract field of featurelayer as object</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/extract-field-of-featurelayer-as-object/m-p/1015295#M71343</link>
      <description>&lt;P&gt;It works, Thank you very Much&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/191789"&gt;@BlakeTerhune&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/11373"&gt;@JohnGrayson&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Jan 2021 01:04:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/extract-field-of-featurelayer-as-object/m-p/1015295#M71343</guid>
      <dc:creator>RabinSubedi</dc:creator>
      <dc:date>2021-01-09T01:04:18Z</dc:date>
    </item>
  </channel>
</rss>

