Select to view content in your preferred language

Query after applyEdits() doesn't contain all new features

1119
8
Jump to solution
06-10-2018 05:20 AM
MichaelLodes2
Occasional Contributor

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

0 Kudos
1 Solution

Accepted Solutions
MichaelLodes2
Occasional Contributor

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);

      });


    })});

View solution in original post

0 Kudos
8 Replies
MichaelLodes2
Occasional Contributor

Nobody out there?

0 Kudos
MichaelLodes2
Occasional Contributor

Robert Scheitlin, GISP‌ Do you know an answer?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

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. 

MichaelLodes2
Occasional Contributor

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?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

I would report it to esri tech support and see if they can reproduce.

0 Kudos
MichaelLodes2
Occasional Contributor

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);

      });


    })});
0 Kudos
MichaelVolz
Esteemed Contributor

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.

MichaelLodes2
Occasional Contributor

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.

0 Kudos