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 have been trying to add an entry to a featureLayer and in want to get a callback from this so I can update another field in it. below is my code

clkListenerAddFeature = dojo.connect(map, "onClick", function (evt)
{
    //alert("inside the click function");
    var point = evt.mapPoint;

    var attributes = {};
    attributes["1"] = "CLOSED";
    attributes["2"] = "DENIED"; 
    attributes["3"] = "0";
    attributes["4"] = "1";
    attributes["5"] = userLoginId;

    var graphic = new esri.Graphic(point, null, attributes);
    featureLayerEdit.applyEdits([graphic], null, null);
    dojo.connect(featureLayerEdit, "onEditsComplete", addResultsComplete);

    if (clkListenerAddFeature) dojo.disconnect(clkListenerAddFeature);
    refresh_map();
    reset_map(map);

});

function addResultsComplete(addResults)
{
    if (addResults.length > 0) {
        var graphic = featureLayerEdit.graphics[featureLayerEdit.graphics.length - 1];

        graphic.attributes["6"] = graphic.attributes["OBJECTID"];
        featureLayerEdit.applyEdits(null, [graphic], null);
    }

}

but I keep hitting this error TypeError: Unable to get value of the property 'getCellsInExtent': object is null or undefined

anyone has any ideas?

share|improve this question
    
I think the error of getCellsInExtent is null or undefined is causing the callback to fail. so if i add a point how should I go about adding it? –  jonleech Dec 28 '12 at 1:52

1 Answer 1

up vote 2 down vote accepted

I think the problem may be with your attributes. Are 1,2,3,4,5 really the field names in your feature service?

It should be something more like

attributes["FIELD_NAME_1"] = "CLOSED";
//equivalent to... 
attributes.FIELD_NAME_1 = "CLOSED";

Btw, instead of connecting onEditsComplete, I find attaching anonymous function to callback and errback more concise/readable.

var d = new Date();
var attr = {
    Created_By: "awesomo",
    Created_Date: d.getTime()
};
var graphic = new esri.Graphic(addGeom, null, attr, null);
featureLayerEdit.applyEdits([graphic], null, null, function (adds, updates, deletes) {
    var query = new esri.tasks.Query();
    query.objectIds = [adds[0].objectId];
    featureLayerEdit.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW);
    alert("Added feature successfully, OBJECTID: " + adds[0].objectId);
}, function (err) {
    //when an error occurs
    alert("Apply Edits Failed: " + err.message);
});
share|improve this answer
    
thanks for the reply, yepp in the end i decided to attach the callback and errback functions to the applyEdits function. –  jonleech Jan 8 '13 at 8:05

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.