Select to view content in your preferred language

onEditsComplete to update another field in the feature

1107
5
12-26-2012 04:08 PM
jonathanlee1
Emerging Contributor
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?
0 Kudos
5 Replies
RuiShen
Occasional Contributor
You can try to put the statement below outside of the Onclick event on map:
  dojo.connect(featureLayerEdit, "onEditsComplete", addResultsComplete);

Also, is "getCellsInExtent" a function in your application?
0 Kudos
JohnGravois
Deactivated User
in the code you supplied, what are you accomplishing by calling applyEdits a second time?
0 Kudos
jonathanlee1
Emerging Contributor
in the code you supplied, what are you accomplishing by calling applyEdits a second time?


I am trying to get the objectId that was generated when I first create the feature and update it to another attribute but concatenating another substring behind the objectId.

P.S: getCellsInExtent isn't a function of mine. this is to answer the reply above. thanks
0 Kudos
JohnGravois
Deactivated User
this is a kinda rough update to one of our published samples, but i didnt have any trouble passing the objectid to another field using your logic.

http://jsfiddle.net/jagravois/5pCWn/2/

maybe you need to try using the draw toolbar?
0 Kudos
JohnGrayson
Esri Alum
You probably don't need 'dojo.connect(featureLayerEdit, "onEditsComplete", addResultsComplete);', instead just use the inline callback function in the applyEdits call.  Also, you're connecting this event many times, once for each map click; not sure if that is making a difference.  I would also hitch the inline calls to make sure you have the proper context.  Also, you need to get the updated feature from the feature layer again as the one currently in memory might not have the correct ObjectID that was assigned on the server.  This last step might not be necessary depending on what you need to do; in your case the ObjectID is provided by the FeatureEditResult object.

featureLayerEdit.applyEdits([graphic], null, null, dojo.hitch(this, function(addResults){
  if(addResult.success){
    var query = new esri.tasks.Query();
    query.objectIds = [addResult.objectId];
    query.outFields = ["*"];       
    featureLayerEdit.queryFeatures(query, dojo.hitch(this, function(featureSet){
      if(featureSet.features.length > 0){    
        var newFeature = featureSet.features[0];
        newFeature.attributes["6"] = addResult.objectId + "_SOMEOTHERVAL";
        featureLayerEdit.applyEdits(null, [newFeature], null);
      }
    }));  
  }
});


I have not tested this, but it should be close to what you need.
0 Kudos