I am trying to delete some records from a feature layer, but I kept getting the error of invalid parameters from the errback.
Below is my code:
function deleteRecords()
{
var incidentId = 2;
var queryTaskDeleteRecords= new esri.tasks.QueryTask(FEATURE_SERVER+"/"+LAYER_V_RECORDS);
var queryDeleteRecords = new esri.tasks.Query();
queryDeleteRecords.outSpatialReference = map.spatialReference;
queryDeleteRecords.returnGeometry = true;
queryDeleteRecords.outFields = ["*"];
queryDeleteRecords.where = FIELD_V_RECORDS_INCIDENTID + " = " + incidentId ;
queryTaskDeleteRecords.execute(queryValveRec,deleteRecordsResults);
}
function deleteRecordsResults(results)
{
var featureLayer= new esri.layers.FeatureLayer( FEATURE_SERVER+"/"+LAYER_V_RECORDS,{
outFields:["*"]
});
for (var i = 0; i < results.features.length; i++)
{
featureLayer.applyEdits(null, null, [results.features[i]], function onComplete(adds, updates, deletes)
{
if (deletes.length > 0)
{
alert("deletes : " + JSON.stringify(deletes));
}
},
function errCallback(err)
{
alert(err);
});
}
}
Is there sometime wrong with the querying of features and passing the features in one by one to applyEdits for deleting?
Best Answer
After searching through the forums, there was a queestion on deleting features from a feature layer and thus I came up with this
and this method works rather than getting features then trying to send to applyEdits. I hope this helps someone cause it took me 2 days to find this insufferable solution.