Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When working with the javascript API, I have been getting an error in FireBug when trying to execute the following script:

var featLayerURL = "";
var featLayer = new esri.layers.FeatureLayer(featLayerURL);

The error returned is "TypeError: featLayer.fields is undefined". At first I thought it was something wrong with one of my server's layers, but after using that sample server and getting the same error, I'm sure there is something else wrong. Here is a link to the REST response: Layer: Recorded Tax Parcel Sales (ID: 1). I have the feeling it is something really simple I'm forgetting, but for now it's been driving me crazy trying to figure it out.

share|improve this question
up vote 3 down vote accepted

This is basically a timing issue. I recreated your sample and it appears that the response has not returned yet so when you immediately check the length you get the error. I moved the alert to its own function and called that function after the page had been initialized and everything worked as expected. If you want data other than the id then you will need to add an option to the constructor that returns all of the fields.

var featLayer = new esri.layers.FeatureLayer(featLayerURL, {
                    outFields: ["*"]

Hope this helps.

share|improve this answer
Jamie is correct, the layer does not load instantly you should be listening to the event to check when it has loaded: aspect.after(layer, "onLoad", lang.hitch(this, function (addlayer) { alert(addlayer.fields.length); }), true); – David Wilton Jan 9 '13 at 10:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.