Select to view content in your preferred language

JavaScript API 2.7 vs. 2.8 - FeatureLayer.applyEdits

5331
15
Jump to solution
04-02-2012 12:39 PM
by Anonymous User
Not applicable
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.
0 Kudos
15 Replies
derekswingley1
Deactivated User
Hi Harold,

Thanks for the additional info. We are looking into a fix.
0 Kudos
gisscconsulting
Emerging Contributor
Yes, that's a layer won't add to map.

"Can you confirm that applyEdits fails ONLY when you haven't added your feature layer to the map? If your featureLayer has been added to the map, and applyEdits is failing, that is a different issue. "

I have exact error that prevents me updating from 2.6 to 2.8.

Look forward to seeing this fixed in next release.

Code break here

var attr = { "USAGE": status, "ACTION":"update"};

var newGraphic = new esri.Graphic(Point, null, attr, null);

featuureLayer.applyEdits([newGraphic], null, null);
0 Kudos
derekswingley1
Deactivated User
Thanks for following up. This will be fixed in the next release of the API.
0 Kudos
ChrisRiver
Occasional Contributor
Thanks for following up. This will be fixed in the next release of the API.


Has this been fixed?

I'm trying to apply edits to a feature layer (without adding it to the map first) and I get "Uncaught TypeError: Object #<Object> has no method '_isWrappable'".

Thanks
0 Kudos
derekswingley1
Deactivated User
We fixed this in 3.0:  http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp/new_v30.html

Specifically:

NIM081335: Feature Layer: applyEdits throws error when called before adding the layer to map
0 Kudos
BillyYancey
Occasional Contributor

As of 3.10, is this issue resolved for tables accessed as FeatureLayers?

I am facing this issue with my tables...

0 Kudos