brightbluesky

How to Delete Records from a Feature Layer?

Discussion created by brightbluesky on Jan 8, 2013
Latest reply on Jan 29, 2013 by amarsden
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 graphicArray = []; 
var valve_suggest_new = new esri.layers.FeatureLayer( FEATURE_SERVER+"/"+LAYER_V_RECORDS,{
        outFields:["*"]
    });

for (var i = 0; i < results.features.length; i++)
{
    var attributes = {};
    attributes[FIELD_V_RECORDS_OBJECTID] = results.features[i].attributes[FIELD_V_RECORDS_OBJECTID];

    var graphic = new esri.Graphic(results.features[i].geometry, null, attributes);

    graphicArray.push(graphic);

}

alert("graphicArray : " + JSON.stringify(graphicArray));
valve_suggest_new.applyEdits(null, null, graphicArray, function onComplete(adds, updates, deletes)
{
    if (deletes.length > 0)
    {
        alert("deletes : " + JSON.stringify(deletes));
    }
},
function errCallback(err)
{
    alert(err);
});


Is my declaration of the graphic array wrong? I did try deleting it graphic by graphic but it still doesn't work.

Outcomes