I'm looking for a little help as I learn JavaScript and the ArcGIS API. I've managed to develop an app that leverages the templatePicker and Editor Widget. But what I am struggling to do is update a couple of the feature's attributes either at the time the feature is added to the FeatureLayer or via a subsequent POST using the applyEdits update that fires after the user completes drawing the feature using the Editor Widget. Currently I am attempting the later by listening for the "onEditsComplete" event, and then if it is an "addResults" type event I would like to access the graphic (that was just added) and to update a couple of it's attributes (e.g. feature creation date field = the current date). some of the applicable code follows:
var map, polyFeatLayer
function init() {
//... other code is in this function like the "onLayerAddResult" listener to initialize template picker/ editor widget, etc.
polyFeatLayer = new esri.layers.FeatureLayer("http://www......../FeatureServer/0", {
mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
outFields: ,
id: "polyFeatLayerId"
});
// note: currently I have not added corresponding ArcGISDynamicMapServiceLayer
dojo.connect(polyFeatLayer, "onEditsComplete", addResultsComplete);
dojo.connect(polyFeatLayer, "onSelectionComplete", selectionComplete);
}
function addResultsComplete(addResults) {
if (addResults.length > 0) {
alert("got Result"); //so far this works
var featLyr = map.getLayer("polyFeatLayerId");
var query = new esri.tasks.Query();
query.where = "OBJECTID = '" + addResults[0].objectId + "'";
featLyr.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW);
}
}
function selectionComplete(features) {
alert("count: " + features.length); // this is 0, unless I close the map.InfoWindow and manually (re)select a feature -- so this is my first problem area ... ???
if (features.length == 1) {
var currentDate = new Date();
var dateString = ((currentDate.getMonth() + 1) + "/" + currentDate.getDate() + "/" + currentDate.getFullYear());
var fixedDate = new Date.parse(dateString);
var polyDesc = document.forms[0].polyDescriptionInput.value;
var feature = features[0];
feature.attributes["DT_ADDED"] = fixedDate;
feature.attributes["POLY_DESC"] = polyDesc;
polyFeatLyr.applyEdits(null, [feature], null); //and this fails too!!! with a "TypeError: that._currentGraphic is undefined"
//
I really appreciate any help and direction with accomplishing this.v/r, jason