AnsweredAssumed Answered

JavaScript API 2.7 vs. 2.8 - FeatureLayer.applyEdits

Question asked by mleahyesri-ca-esridist Employee on Apr 2, 2012
Latest reply on Sep 4, 2014 by epeconsulting
Hello all,

Has anyone had any issues running applyEdits on feature layers since the update to version 2.8 of the API?  I find that with versions 2.7 or earlier, I could execute applyEdits() on a FeatureLayer object, even if the layer hasn't been added to a map, with essentially two lines of code:

var featureLayer = new esri.layers.FeatureLayer(url,{<opts>});
featureLayer.applyEdits([newGraphic],null,null,function(addResults){ // verify results });

However, when I try this in 2.8, and if the layer is not already added to a map object, I get an error message that looks like:

----- TypeError: arr is undefined http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.8 Line 14 -----


I've found that the only way to work around this is to actually add the layer to the map (even if I don't necessarily want it displayed to the user), then run applyEdits...but this makes things a bit more complicated.  Basically, after creating the layer, I need to connect to the onLayerAddResult function and run applyEdits within that callback event...when the callback is fired, I can remove the layer again (if I don't want to keep it in the map), and disconnect from the event.  Once that is setup, I finally add the layer to the map and wait for the callback to execute.

var featureLayer = new esri.layers.FeatureLayer(url,{<opts>,visible:false}); var listener = dojo.connect(map,"onLayerAddResult",this,function(layer){  if (layer==featureLayer)  {   dojo.disconnect(listener);   featureLayer.applyEdits([newGraphic],null,null,function(addResults){ // verify results });   map.removeLayer(featureLayer);  } }); map.addLayer(featureLayer);


My guess is that this is a result of one of the two following fixes/enhancements listed for version 2.8:


  • NIM079205: Enhance feature layer to support editor tracking

  • NIM079209: Do not serialize non-editable fields from a feature layer in applyEdits


If it's the latter, then I would suspect that the error is happening because the FeatureLayer has not yet retrieved the metadata from the FeatureLayer's REST service, and that this only happens after the layer gets added to a map.

Should it still be possible to applyEdits on a layer that is not added to a map object first?  Alternatively, is there a better way I can do this?

Thanks for any advice.

Outcomes