callback for applyEdits not working

3109
4
Jump to solution
01-14-2014 05:39 AM
KaitlynnDavis
Occasional Contributor
I added a 'save' button to my attribute inspector, and upon clicking it I'd like for the feature layer to update and then close the info window (a similar effect to when you hit the attribute inspector's 'delete' button). I followed the documentation (https://developers.arcgis.com/en/javascript/jsapi/featurelayer.html#applyedits)and came up with the following statement:

updateFeature.getLayer().applyEdits(null, [updateFeature], null, function(){  map.infoWindow.hide();         });


The update is fine but the callback does not occur. The syntax looks correct to me, I don't see the need to supply any arguments to the callback, so I don't know what the problem could be
0 Kudos
1 Solution

Accepted Solutions
JonathanUihlein
Esri Regular Contributor
In the documentation you linked, you'll notice that applyEdits returns a deferred.

Edit your code to handle the deferred... try something like this:

        myLayer.applyEdits(null, [updateFeature], null).then(function(addResponse, updateResponse, deleteResponse){           console.log(addResponse, updateResponse, deleteResponse);         });


NOTE: Only updateResponse will have data (since you did not add or delete, both addResponse and deleteResponse will be null).

*edit
I also want to mention that you linked to the old style (legacy) documentation of FeatureLayer.
I would recommend switching over to AMD style.

View solution in original post

0 Kudos
4 Replies
ReneRubalcava
Frequent Contributor
Try adding a 2nd function after the callback to listen for a possible error and see if there is more information.
updateFeature.getLayer().applyEdits(null, [updateFeature], null, function(){
 map.infoWindow.hide();        
}, function(err) {
    console.warn('Error occured: ', err);
});
0 Kudos
KaitlynnDavis
Occasional Contributor
I tried to handle the error and no warnings were issued in Firebug, but thank you for the good suggestion
0 Kudos
JonathanUihlein
Esri Regular Contributor
In the documentation you linked, you'll notice that applyEdits returns a deferred.

Edit your code to handle the deferred... try something like this:

        myLayer.applyEdits(null, [updateFeature], null).then(function(addResponse, updateResponse, deleteResponse){           console.log(addResponse, updateResponse, deleteResponse);         });


NOTE: Only updateResponse will have data (since you did not add or delete, both addResponse and deleteResponse will be null).

*edit
I also want to mention that you linked to the old style (legacy) documentation of FeatureLayer.
I would recommend switching over to AMD style.
0 Kudos
KaitlynnDavis
Occasional Contributor
@ jon.uihlein, it has been a while but your suggestion was what ended up working for me. I used the then() callback to close my infoWindow immediately after the applyEdits function executes. Thanks for your help
0 Kudos