2

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?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jan 8, 2013 at 8:39

1 Answer 1

2

After searching through the forums, there was a queestion on deleting features from a feature layer and thus I came up with this

var id = 2;
var query = new esri.tasks.Query();
query.where = FIELD_ID + " = " + id ; //the valve ops rec layer thus using the val ops rec incident id
var featureLayer = new esri.layers.FeatureLayer(FEATURE_SERVER +"/"+LAYER_V_REC,
{
 outFields:["*"]
});
featureLayer.selectFeatures(queryValveRec, esri.layers.FeatureLayer.SELECTION_NEW, 
function (features)
{
 for (var i = 0; i < features.length; i++)
 {
 featureLayer.applyEdits(null, null, [features[i]], function (adds, updates, deletes)
 {
 alert("adds : " + JSON.stringify(adds));
 alert("updates : " + JSON.stringify(updates));
 alert("deletes : " + JSON.stringify(deletes));
 }, 
 function (err)
 {
 alert(err);
 });
 }
});

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.

answered Jan 10, 2013 at 3:41
2
  • When you get a chance I recommend that you Accept your own Answer here - just click the green tick next to it. Commented Jun 15, 2014 at 11:14
  • Alright will do :D Commented Jun 16, 2014 at 2:17

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.