Select to view content in your preferred language

featureLayer.applyEdits ignores 3rd delete array

386
1
Jump to solution
12-22-2022 03:19 AM
ViktorSafar
Frequent Contributor
JS API v3
 
docs say the 3rd param is <Graphic[]> deletes, and the only specified requirement is "Array of features to delete. Must have valid ObjectId"
 

 

    const toDelete = new esriJS.EsriGraphic();
    toDelete.setAttributes({})
    toDelete.attributes.objectid = objectid;
    const featureLayer = new esriJS.FeatureLayer(featureLayerUrl);
    featureLayer.applyEdits(null, null, [toDelete],
      (adds, updates, deletes) => {
        resolve(deletes);
      },
      err => {
        console.log(err);
        debugger
        reject(err);
      });

 

 
(my layer's objectIdField is called objectid (all lower case)).
ViktorSafar_1-1671707913605.png

 

I can see that the function makes the POST but ignores the [toDelete] parameter that was passed in. What am I doing wrong?
 
ViktorSafar_2-1671707969161.png

 


 

 
0 Kudos
1 Solution

Accepted Solutions
JoelBennett
MVP Regular Contributor

In order for the applyEdits operation to successfully process the deletes, the objectIdField must be set.  Although I suppose you could manually set it, this ordinarily doesn't take place until the layer has loaded.  Therefore, I would recommend something like the following change:

const featureLayer = new esriJS.FeatureLayer(featureLayerUrl);
featureLayer.on("load", function() {
	featureLayer.applyEdits(null, null, [toDelete], (adds, updates, deletes) => {
		resolve(deletes);
	}, err => {
		console.log(err);
		debugger
		reject(err);
	});
});

Waiting for the layer to load before calling applyEdits may also solve the problem you were having in the other thread.

View solution in original post

1 Reply
JoelBennett
MVP Regular Contributor

In order for the applyEdits operation to successfully process the deletes, the objectIdField must be set.  Although I suppose you could manually set it, this ordinarily doesn't take place until the layer has loaded.  Therefore, I would recommend something like the following change:

const featureLayer = new esriJS.FeatureLayer(featureLayerUrl);
featureLayer.on("load", function() {
	featureLayer.applyEdits(null, null, [toDelete], (adds, updates, deletes) => {
		resolve(deletes);
	}, err => {
		console.log(err);
		debugger
		reject(err);
	});
});

Waiting for the layer to load before calling applyEdits may also solve the problem you were having in the other thread.