Retrieve single column data of a feature layer .

2976
12
Jump to solution
12-02-2018 01:48 AM
Jayendra_Praveen_KumarChorapal
New Contributor

Hey i am working on a feature layer and i would like to have the all the tuple values of a single column of my feature layer so that i will use these tuples to insert in a drop down list for my web app. I hope for a quick reply.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Jayendra,

Getting values from a single column is a fairly simple task with a QueryTask in the JS API.

The returned value of a QueryTask is a FeatureSet (which is an Array of Graphics) a tuple is something in Python and other languages though, not JavaScript.

require([
  "esri/tasks/query", "esri/tasks/QueryTask", ... 
], function(Query, QueryTask, ... ) {
  var query = new Query();
  var queryTask = new QueryTask( ... );
  query.where = "STATE_NAME = 'Washington'";
  query.outSpatialReference = {wkid:102100}; 
  query.returnGeometry = true;
  query.outFields = ["CITY_NAME"];
  queryTask.execute(query, addPointsToMap);
  ...
});

This will return the CITY_NAME filed from the Map Service that has a STATE_NAME of Washington.

View solution in original post

12 Replies
RobertScheitlin__GISP
MVP Emeritus

Jayendra,

Getting values from a single column is a fairly simple task with a QueryTask in the JS API.

The returned value of a QueryTask is a FeatureSet (which is an Array of Graphics) a tuple is something in Python and other languages though, not JavaScript.

require([
  "esri/tasks/query", "esri/tasks/QueryTask", ... 
], function(Query, QueryTask, ... ) {
  var query = new Query();
  var queryTask = new QueryTask( ... );
  query.where = "STATE_NAME = 'Washington'";
  query.outSpatialReference = {wkid:102100}; 
  query.returnGeometry = true;
  query.outFields = ["CITY_NAME"];
  queryTask.execute(query, addPointsToMap);
  ...
});

This will return the CITY_NAME filed from the Map Service that has a STATE_NAME of Washington.

Jayendra_Praveen_KumarChorapal
New Contributor

Sir,

The table of my feature layer has been attached under this.I would like

to retrieve the NAME_OF_THE_SCHOOL column data of that table and insert

each value of that column in a drop down list in my website.As far as your

concerns about selecting a particular record in a column but i would like

to retrieve the entire column data.

I hope for a quick reply sir.

On Mon, Dec 3, 2018 at 10:09 AM Robert Scheitlin, GISP <geonet@esri.com>

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jayendra,

   OK, So here is a full sample for adding a fields unique values to a dropdown.

<!DOCTYPE html>
<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no" />
  <title>Drop Down Test</title>
  <link rel="stylesheet" href="http://js.arcgis.com/4.9/dijit/themes/claro/claro.css">
  <link rel="stylesheet" href="https://js.arcgis.com/4.9/esri/css/main.css">
  <script src="https://js.arcgis.com/4.9/"></script>
  <style>
    html,
    body,
    #mainWindow {
      height: 100%;
      width: 100%;
      margin: 0;
      padding: 0;
    }
    body {
      background-color: #FFF;
      overflow: hidden;
      font-family: "Trebuchet MS";
    }
    #header {
      height: 3%;
      overflow: auto;
    }
  </style>

  <script>
    var map;
    require([
      "esri/Map",
      "esri/views/MapView",
      "dojo/on",
      "esri/tasks/support/Query",
      "esri/layers/FeatureLayer",
      "dojo/store/Memory",
      "dojo/_base/array",
      "dojo/_base/lang",
      "esri/request",
      "dojo/parser",
      "dijit/registry",
      "dijit/layout/BorderContainer",
      "dijit/layout/ContentPane",
      "dijit/form/Button",
      "dijit/form/ComboBox",
      "dojo/domReady!"
    ], function(
      Map, MapView, on, Query, FeatureLayer, Memory, array, lang, esriRequest, parser, registry
    ) {
      parser.parse();
      map = new Map({
        basemap: "topo"
      });

      var view = new MapView({
        container: "map",
        map: map,
        center: [-98.1883, 37.0868],
        zoom: 5
      });

      esriRequest('http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3/query?where=1%3D1&outF...',
      {
        responseType:'json',
        timeout:15000
      }).then(lang.hitch(this,function(response){
        var store2 = new Memory({data:[]});
        registry.byId("stateSelect").set('store',store2);
        var data = array.map(response.data.features,lang.hitch(this,function(feat, index){
          var name = feat.attributes.STATE_NAME;
          var value = feat.attributes.STATE_NAME;
          var dataItem = {
            id:index,
            name:name,
            value:value
          };
          return dataItem;
        }));
        store2 = new Memory({data:data});
        registry.byId("stateSelect").set('store',store2);
      }));
    });
  </script>
</head>

<body class="claro">
  <div id="mainWindow" data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline', gutters:false" style="padding:0px;margin:0px;">
    <div id="header" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'top'" style="overflow:hidden;border:none;border-bottom: 3px solid #CC9900;font-family: Windows;font-size:14pt; color: #FFFFFF;background: #000000; "> Select a State:
      <input id="stateSelect" data-dojo-type="dijit/form/ComboBox" value="Select State"  data-dojo-props="maxHeight: 200" />
      <input type="hidden" name="stateabbr" id="stateabbr" />
    </div>
    <div id="map" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'left'" style="width:100%;height:95%;border:none;padding:0px;margin:0px;"></div>
  </div>
</body>

</html>
0 Kudos
Jayendra_Praveen_KumarChorapal
New Contributor

Sir,

My application is real time sir the values of my column keeps on increasing

if schools get registered .

so i cant directly give the json url in my code because it only has the

school data at that point of time . if any new school gets registered in my

website i cant find them in the drop down list.

can u please provide me a solution for this.

On Mon, Dec 3, 2018 at 10:43 AM Robert Scheitlin, GISP <geonet@esri.com>

0 Kudos
Jayendra_Praveen_KumarChorapal
New Contributor

So that what i would like perform query for retrieving the single column

data and i will generate a drop down list of that data

What actually im looking is a line that seems to be SELECT

NAME_OF_THE_SCHOOL from TABLENAME as in sql which gives all the records in

that column

On Mon, Dec 3, 2018 at 11:59 AM Chorapalli Jayendra praveen kumar <

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jayendra,

  You do not have the ability to do a raw SQL select in the JavaScript API. you only have access to the Where clause portion of the SQL.

Have you seen the JS API documentation?

JS API 3.x

QueryTask | API Reference | ArcGIS API for JavaScript 3.26 

Query | API Reference | ArcGIS API for JavaScript 3.26 

JS API 4.x

QueryTask | API Reference | ArcGIS API for JavaScript 4.9 

Query | API Reference | ArcGIS API for JavaScript 4.9 

0 Kudos
Jayendra_Praveen_KumarChorapal
New Contributor

Sir thank you for the information.

and While accessing directions through sandbox

It is asking my Arcgis online credentials and I’ve entered the esri

provided and things are going good in sandbox

But when I use the code in my document and just try to open it in a browser

It’s asking for Arcgis online credentials and I’m entering the same

credentials that esri provided which I’ve entered in the sandbox but the

popup box is saying that the username and password are incorrect ?

I am having credits in my account too.

My credentials are working in sandbox and Arcgis Devlabs also

But when loading the same code in a file and trying it open it in a browser

the popup is notifying me that the invalid username and password.

I dont know whats wrong is going with the same code.

Looking forward for your reply sir

On Mon, Dec 3, 2018 at 7:41 PM Robert Scheitlin, GISP <geonet@esri.com>

0 Kudos
Jayendra_Praveen_KumarChorapal
New Contributor

Sir,

In the sample code

there is a hidden input field and i would like to use it use it as text

field used to display the selected elements value in drop-down list.

I have tried but its not working.

I hope you help me out from this. here im trying to show the emil of the

school selected from the drop downlist

esriRequest('

https://services9.arcgis.com/2882Ggz2LB0PQSyP/arcgis/rest/services/school/FeatureServer/0/query?where=OBJECTID%3E0&objectIds=&time=&geometry=&geometryType=esriGeometryPoint&inSR=&spatialRel=esriSpatialRelIntersects&resultType=none&distance=0.0&units=esriSRUnit_Meter&returnGeodetic=false&outFields=NAME_OF_THE_SCHOOL%2CEMAIL_ADDRESS_OF_THE_SCHOOL&returnHiddenFields=false&returnGeometry=false&multipatchOption=xyFootprint&maxAllowableOffset=&geometryPrecision=&outSR=&datumTransformation=&applyVCSProjection=false&returnIdsOnly=false&returnUniqueIdsOnly=false&returnCountOnly=false&returnExtentOnly=false&returnDistinctValues=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&having=&resultOffset=&resultRecordCount=&returnZ=false&returnM=false&returnExceededLimitFeatures=true&quantizationParameters=&sqlFormat=none&f=pjson&token=XOpDCWQjd4GHcexTq23FjrCNDHt8CVYZI4-g2KhpaPEuwP8hpnWtUiH2FK1zh7wsfKJ8-Y3G4cHl1v_M-AWfFBZsH7PS9n3wp-F8ZhDddn5lJ5ukhKRnyHp5mvkJ6fyx61GD28PFbw6cAH5FA7mubsYcsjj-L5poA9KyBWSmZfknKJ41pYXSOa0-d7IeIfUyZuBkdkx0poaUttA1Bkdj8Hzm3jdvxLRe_Ke-UoPuHv_wsAJgoq3rJatPvwnSNYAU

',

).then(lang.hitch(this, function (response) {

var store2 = new Memory({ data: [] });

registry.byId("stateSelect").set('store', store2);

var data = array.map(response.data.features, lang.hitch(this, function

(feat, index) {

var name = feat.attributes.NAME_OF_THE_SCHOOL;

var value = feat.attributes.EMAIL_ADDRESS_OF_THE_SCHOOL;

alert(value);

var dataItem = {

id: index,

name: name,

value: value

};

// console.log(dataItem.value);

return dataItem;

}));

store2 = new Memory();

registry.byId("stateSelect").set('store', store2);

}));

});

On Wed, Dec 5, 2018 at 5:18 PM Chorapalli Jayendra praveen kumar <

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jayendra,

 When your original question has been answered you should mark the question as answered by licking on the "Mark Correct" link on the reply that answered your question.

Then if you have another question you start a new question and ask there. If you do decide to start a new thread make sure you specify if you want the EMAIL_ADDRESS_OF_THE_SCHOOL to be shown in the dropdown or the NAME_OF_THE_SCHOOL.

0 Kudos