How to retrieve the Fields available in a Dynamic map's sub-layers

Discussion created by stevel on Aug 15, 2011
Latest reply on Nov 21, 2011 by amarsden
See the sample below, which adds a DynamicMapServiceLayer to a map using the URL:

Navigating to this REST endpoint in a browser shows the component Layers, and each layer's Fields.

How can I retrieve this information programatically? I need a list of the available layers (0,1,2) and each layer's available fields (eg layer 0 contains objectid, lifecyclestatus, incident_number, etc)

My goal is to add this information to a Query function, so I need to know that I can search layer 1 for the field collection_time, etc.

Looping through the layerInfos tells me about each available layer - how can I retrieve information on the fields? (One option is to create a new feature layer from each layer and add it to the map, but I'd really like to avoid this workaround).


    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" />
    <!--The viewport meta tag is used to improve the presentation and behavior of the samples 
      on iOS devices-->
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
    <title>layer infos</title>
    <link rel="stylesheet" type="text/css" href="">
    <script type="text/javascript" src=""></script>
    <script type="text/javascript">

      function init() {
        var map = new esri.Map("map");
        var basemap = new esri.layers.ArcGISTiledMapServiceLayer("");

        var url = "";
        var dynLayer = new esri.layers.ArcGISDynamicMapServiceLayer(url);

        dojo.connect(dynLayer, "onLoad", function() {
            var infos = dynLayer.layerInfos;
            for (var i = 0; i <= infos.length - 1; i++) {
                var layerId = infos[i].id;
                var restEndPoint = url + layerId;

                //restEndPoint is the layer's URL - how can I retrieve its fields?


  <body class="claro">
    <div id="map" style="width:900px; height:600px; border:1px solid #000;"></div>