FeatureLayer.applyEdits(...) causes error "TypeError: _178.geometry is null"

749
2
11-28-2012 06:28 AM
ThomasLaue
New Contributor II
Hello,

I am trying to update an existing feature using the following peace of code:

var selectedTourSection = layerUtilProvider.getSelectedFeatures();
if (selectedTourSection.length > 0) {
     selectedTourSection[0].attributes.STATUS = 1;
                
     selectedOperationalLayer.applyEdits(null, [selectedTourSection[0]], null,
           function () {
               isTourSectionSelected = true;
           },
           function (error) {
               console.log(error);
            });


My feature "selectedTourSection" has a valid geometry assigned to it (checked using Firebug). The "applyEdits" functions even returns with success (response taken from Firebug):

[HTML]
addResults[]
updateResults[Object { objectId=2,  success=true}] ...
deleteResults[]
[/HTML]

but nevertheless the following error appears in the Firebug console:

[HTML]
TypeError: _178.geometry is null
[/HTML]

I have no idea what is actually causing this problem. I would be thankful if anyone could shed some light on this issue. Thank you very much in advance.

Thomas
0 Kudos
2 Replies
ReneeMaxwell
Occasional Contributor
FYI, I have encountered the same error under the same circumstances. It seems related to the use of featureLayer.getSelectedFeatures() to define the graphic. I have a function that fires whenever a feature is selected in my featureLayer, and that function is being triggered by the applyEdits() function somehow.

Pretty strange behavior.
0 Kudos
ReneeMaxwell
Occasional Contributor
I seem to have found a fix, assuming our problems are related.

I was getting errors whenever I used getSelectedFeatures() to return a graphic and then pass that graphic to applyEdits(). Try using featureLayer.clearSelection() before you call applyEdits(). That seems to do the trick.

In my case, I noticed that every time I called applyEdits(), the feature I just updated/deleted was firing 'onSelectionComplete', which would return null and throw errors. I have no idea why using getSelectedFeatures() before applyEdits() triggers a feature selection upon 'onEditsComplete', but there it is.

I hope that helps!
0 Kudos