Select to view content in your preferred language

Unable to applyEdits FeatureLayer

1308
5
05-04-2022 12:06 AM
utility9213
Emerging Contributor

Good Evening,

I am trying to update my featureLayer using the applyEdits properties. I am facing some issues as I cannot change the value of the specific layer. I am not sure what is wrong here do assist me on this, cheers! (This project is running on ArcGIS API 3.25

    let testButton = document.getElementById('testButton')
    if (testButton){
    testButton.addEventListener("click",function(){
      var announcementInput = document.getElementById('announcementInput').value;
      console.log(announcementInput)
 
      featureLayer.applyEdits(
                  null,
                  [{
                    "attributes":{
                      "objectid":objectid,
                      "announcement": announcementInput, // I want to update this value
                  }
                  }],
                  null,
                  null,
                  null
    })
    }
    else{
      console.log("Not working")
    }
      });
    });
0 Kudos
5 Replies
JillianStanford
Frequent Contributor

Hi,

If you're making updates, each feature has to have a valid ObjectID. In the code above, you have that value commented out. What happens if you include it?

Jill

0 Kudos
utility9213
Emerging Contributor

Hello, even when I put in the ObjectID nothing is updated..

0 Kudos
JillianStanford
Frequent Contributor

Hi,

What is the response that you're getting?

Can you perform the applyEdits operation in the REST Service Directory to validate your parameters?

0 Kudos
UndralBatsukh
Esri Regular Contributor

Hi there, 

Please take a look at the FeatureLayer.applyEdits doc. To update features, you must pass in array or collection of features! So you have to update your code to query the features your want to update, then update the attributes of the features and pass in those features to the FeatureLayer's updateFeatures param. 

So you'd have to something like the following: 

// editFeature is a feature you got from your feature layer
editFeature.attributes[announcement] = newAnnouncement;
// Setup the applyEdits parameter with updates.
const edits = {
 updateFeatures: [editFeature]
};
featureLayer.applyEdits(edits).then((editsResult) => {
  console.log(editResult);
})
.catch((error)=>{
  console.log(error);
});

 

Please take a look at the following two samples as they both use FeatureLayer.applyEdits:

https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=editing-applyedits

 https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=layers-featurelayer-coll...

 

utility9213
Emerging Contributor

Sorry, I am currently using arcgis api 3.25 I forget to mention this earlier. But thank you for your solution!

0 Kudos