Hello all,
directly after creating and updating my hosted Featurelayer with applyEdits(), I would like to get the whole updated Featurelayer by a Query.
My code below does this task chain almost correctly, but sometimes it doesn't get all changes. I guess the db update by applyEdits() was not ready yet before quering it. Why? I use then() between the functions, so I thougt one function is executed when the function before has done everything correctly?
lyr.applyEdits({
addFeatures: createFeatArr
}).then(
lyr.applyEdits({
updateFeatures: updateFeatArr
})).then(getFeatureIds(lyr));
getFeatureIds(lyr):
function getFeatureIds(lyr){
var query = new Query();
query.where = "1=1";
query.outFields = ["MYSQLID", "FID"];
var featuresArray = new Array();
var arr = new Array();
lyr.queryFeatures(query).then(function(results){
results.features.forEach(function(item){
featuresArray.push(item.attributes);
});
for (var prop in featuresArray) {
arr[featuresArray[prop].FID] = featuresArray[prop].MYSQLID.toString();
}
console.log("arr: " + arr);
});
}
Someone can help me?
Kind Regards
Michael
Solved! Go to Solution.
I talked to esri support, they provided the solution for me. There have to be return commands when chaining promises. Like:
lyr.queryFeatures(query)
.then(function(results) {
var featuresArray = new Array();
results.features.forEach(function(item) {
featuresArray.push(item.attributes);
});
})
//adding features
.then(function(results) {
return lyr.applyEdits({
addFeatures: createFeatArr
})})
//then updating features
.then(function(results) {
return lyr.applyEdits({
updateFeatures: updateFeatArr
})})
//and then quering featurelayer
.then(function(results) {
lyr.queryFeatures(query)
.then(function(results) {
var featuresArray = new Array();
results.features.forEach(function(item) {
featuresArray.push(item.attributes);
});
})});
Nobody out there?
Robert Scheitlin, GISP Do you know an answer?
Michael,
No I don't. I would think the same as you that after the deferred is returned that the data should be query-able.
After doing different tests I guess that the Promise returned by adding a feature with applyEdits(), is set too early to the "OK" status. Is this a bug?
I would report it to esri tech support and see if they can reproduce.
I talked to esri support, they provided the solution for me. There have to be return commands when chaining promises. Like:
lyr.queryFeatures(query)
.then(function(results) {
var featuresArray = new Array();
results.features.forEach(function(item) {
featuresArray.push(item.attributes);
});
})
//adding features
.then(function(results) {
return lyr.applyEdits({
addFeatures: createFeatArr
})})
//then updating features
.then(function(results) {
return lyr.applyEdits({
updateFeatures: updateFeatArr
})})
//and then quering featurelayer
.then(function(results) {
lyr.queryFeatures(query)
.then(function(results) {
var featuresArray = new Array();
results.features.forEach(function(item) {
featuresArray.push(item.attributes);
});
})});
Are you working with versioned SDE data? Maybe the A and D table records are not available unless you can compress the database so the A and D records are moved to the default version of the SDE database. Just a theory that you might try testing.
I don't know "versionded SDE data" and "A and D table records". I am working with ArcGIS Online "Feature Layer (hosted)".
Thank you for your answer, Michael.