AnsweredAssumed Answered

Get fields from featureLayer created from rest service?

Question asked by vlantaca on Dec 4, 2019
Latest reply on Dec 4, 2019 by kenbuja

I am trying to figure out a good way to retrieve the fields from an ArcGIS REST service. I first create a FeatureLayer from the a feature server url. When I console.log the feature layer, I see that it has fields, but when I try to console.log(featureLayer.fields) it is just null.


I need the field information to create a popup template, but I am trying to find a way to avoid having to hard-code the field information. What is a good way of going about this? 


<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
            padding: 0;
            margin: 0;
            height: 100%;
            width: 100%;

    <link rel="stylesheet" href="">
    <script src=""></script>
<div id="viewDiv"></div>
    ], function(Map, MapView, Legend, PopupTemplate, FeatureLayer, Graphic){

        var map = new Map({
            basemap: "gray"

        var view = new MapView({
            container: "viewDiv",
            map: map

        var featureLayer = new FeatureLayer({
            url: ""


        // add the layer to the map