Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
2  
thanks for sharing : ) –  Sunil Jan 10 '13 at 12:50
    
When you get a chance I recommend that you Accept your own Answer here - just click the green tick next to it. –  PolyGeo Jun 15 at 11:14
    
Alright will do :D –  jonleech Jun 16 at 2:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.