AnsweredAssumed Answered

Get FeatureLayer Attribute by Clicking

Question asked by xuankuai on Jul 30, 2018
Latest reply on Jun 4, 2019 by soewai53

I'm using ArcGIS API for JavaScript 4.8. My goal is to get the Census tract ID value of the clicked Feature in a FeatureLayer and display the ID value in an alert box. I got stuck when trying to use Query/QueryTask to fetch the value. My code goes here:


    Map, MapView, FeatureLayer, GroupLayer, LayerList, Query, QueryTask, on
  ) {
    var map = new Map({
      basemap: "topo"

    var view = new MapView({
      center: [-91.05, 30.5161109],
      zoom: 11,
      container: "viewDiv",
      map: map,

    // Generate link to Census tract details
    view.when(function() {
      on(view, "click", displayTractID);

    function displayTractID(event) {
      // TODO

    // Define popup template and get feature layers
    var census2000Template = {
      title: "Census 2000",
      content: [{
        type: "fields",
        fieldInfos: [{
          fieldName: "TRACT",
          label: "Tract",
          visible: true
        }, {
          fieldName: "POPULATION",
          label: "Population",
          visible: true,
          format: {
            digitSeparator: true,
            places: 0

    var census2000Layer = new FeatureLayer({
      url: "",
      outFields: ["*"],
      popupTemplate: census2000Template

    // Add feature layers to a group layer
    var censusGroupLayer = new GroupLayer({
      title: "Historic Census",
      visible: true,
      visibilityMode: "exclusive",
      layers: [census2000Layer]



Could someone help me to fill out the TODO part or show me some sandbox examples?