Select to view content in your preferred language

applyEdits fails in JSAPI

3132
3
09-28-2015 12:34 PM
BillyYancey
Occasional Contributor

I am using a feature layer in JSAPI, where I edit a feature by the standard selection, change attributes, applyEdits process. It seems that there is a bug in JSAPI both 3.12 and 3.14 which makes the apply edits fail on certain features. The callback just errors out without any clue.

The interesting observations:

1. Failure only happens on certain features and all cases belong to a particular layer (other features in that layer are just fine).

2. Changing from 3.12 to 3.14 the features that cause the error are changed but did not go away.

Here is a quick snippet of the code:

sq = buildSelectionQuery();
if (sq) {
    all(assetsFeatureLayers.map(function (l) { return l.selectFeatures(sq, esri.layers.FeatureLayer.SELECTION_NEW).promise;})
    ).then(function (fls) {
        console.log('sel res', fls);
        all(fls.map(function (r, i) {
            var fs = r[0]; // the first is an array of selected features
            var l = assetsFeatureLayers;
            console.log(fs);
            if (fs.length > 0) {
                console.log("Switching phases to: ", tph);
                fs.forEach(function (f) {
                    f.attributes['phasecode'] = tph;
                });
                console.log("Saving switched phases for layer: ", l.name);
                return l.applyEdits(null, fs, null); //.promise;
            } else {
                return null;
            }
        })).then(function (l) {
            console.log("Phase switching finished successfully!", l);
            clearAllSelections();
        }, function (e) {
            console.log("Error switching phases!", e);
            clearAllSelections();
        });
    });
}
0 Kudos
3 Replies
DavinShokes1
Frequent Contributor

FeatureLayer.applyEdits() always erroring on update when it actually worked see Ben Fousek 's

  1. this.applyEdits(null, [feature], null, function (a, u, d) { 
  2.     console.log(u[0]); 
  3.   }, function (error) { 
  4.     console.log(error); 
  5.   });
0 Kudos
BillyYancey
Occasional Contributor

I actually found the root cause and it was the PHP proxy, updating it to the latest beta solved the issue.

0 Kudos
DavinShokes1
Frequent Contributor

Ah cool.

0 Kudos