Can't delete selected feature

4969
6
03-07-2012 09:48 AM
KathleenBrenkert
Occasional Contributor
I can update and add to my featurelayer, but when I try to delete I get FaultCode 400 invalid parameters.  I can't figure out what I am doing wrong.

var deleteGraphic:Graphic=new Graphic();
deleteGraphic.attributes={OBJECTID:logBook.selectedFeatures[0].attributes.OBJECTID};
const deletes:Array=[deleteGraphic];
logBook.applyEdits(null,null,deletes, new AsyncResponder(deleteComplete, deleteFail));
Tags (2)
0 Kudos
6 Replies
IvanBespalov
Occasional Contributor III
Kathleen,

Your fault in creating new deletes array.
Try it:
if (logBook.selectedFeatures.length > 0)
{
    var selectedGraphic:Graphic = logBook.selectedFeatures[0];

    var deletes:Array = new Array(selectedGraphic);

    logBook.applyEdits(null, null, deletes, new AsyncResponder(onEditResult, onEditFault));
}
0 Kudos
KathleenBrenkert
Occasional Contributor
Thanks but I still get the same error.  I've created a work around where I update the record with 'blank' data, so it appears to have been deleted when the queries run.  Not ideal b/c I'll have to clean up all the blank records, but at least it will work until I can figure out why it won't delete.
0 Kudos
IvanBespalov
Occasional Contributor III
Kathleen,

1 - Can you delete feature using "ArcGIS Services Directory"?
http://server name/ArcGIS/rest/services/service name/FeatureServer/0/applyEdits


2 - applyEdits(adds:Array, updates:Array, deletes:Array, responder:IResponder = null):AsyncToken
deletes:Array â?? Array of features to delete. Must have valid objectId.

so try validate feature object id:
if (logBook.selectedFeatures.length > 0)
{
    var selectedGraphic:Graphic = logBook.selectedFeatures[0];
    var attributes:Object = selectedGraphic.attributes;

    var oidField:String;
    var oidValue:Number;
    
    if (logBook.layerDetails != null)
    {
        oidField = logBook.layerDetails.objectIdField;
    }
    
    if (oidField != null)
    {
        if (attributes != null && attributes.hasOwnProperty(oidField))
        {
            oidValue =attributes[oidField];
        }
    }
    else
    {
        trace("Something wrong with layer objectId field");
    }

    if (oidValue != null && oidValue > 0)
    {
        var deletes:Array = new Array(selectedGraphic);

        logBook.applyEdits(null, null, deletes, new AsyncResponder(onEditResult, onEditFault));
    }
    else
    {
        trace("Selected feature has no objectId value and can not be deleted!");
    }
}
0 Kudos
RuiShen
New Contributor III
Simply try
logBook.applyEdits(null, null, logBook.selectedFeatures);
0 Kudos
HaroldBostic
Occasional Contributor II
Hello, I'm having the same issue.  It appears the API is not posting my deleted array, as looking at the POST in firebug only shows f=json.  Trying to delete using the REST services itself gives me an error message that says 'objectIds' parameter is invalid.

I'm building my own delete array so I have not tried selecting the features then trying to delete them.

Any help would be gladly appreciated
0 Kudos
HaroldBostic
Occasional Contributor II
0 Kudos