I am trying to update multiple features in a feature layer through a loop.

I have a feature layer that I would like to select and then assign someone to the features (through an attribute update. I can select the features and see all of the attributes but I can't figure out how to update the the features. See below for a sample of what I am trying to do. Right now it is a bit messy where I am trying to set the visibility of a form and button on after the selection so the user can choose an assignment.

Has anyone updated multiple features without using the attribute inspector or editor widget which I have only seen examples for editing a feature at a time.

 var map, geocoder, currentBaseMap, assignWindow, featureLayer;
 var locatorUrl ="http://gisaprd/ArcGIS/rest/services/SDE.AddressLocator_Comp/GeocodeServer";
 var selectedPoints = new Array();

 function (
 InfoTemplate, Map, FeatureLayer, ArcGISTiledMapServiceLayer, ArcGISDynamicMapServiceLayer,         Geocoder, SimpleFillSymbol, SimpleLineSymbol,
Query, Draw, dom, on, parser, arrayUtil, Color
 ) {


  var selectionToolbar, featureLayer;

  // Create the map
  map = new Map("map")

  aerialsLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://gisaprd/ArcGIS/rest/services/Aerials_4inch_12inch_Cached/MapServer", { "id": "Aerials", "visible": false });

  streetsLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://gisaprd/ArcGIS/rest/services/SRSLandbase/MapServer", { "id": "Streets" });
  currentBaseMap = "Streets";

  map.on("load", initSelectToolbar);

  document.getElementById("AssignFrm").style.visibility = "hidden";
  document.getElementById("AssignBTN").style.visibility = "hidden";

  highlightSymbol = new esri.symbol.SimpleMarkerSymbol().setColor(new dojo.Color([255, 255, 0]));

  var content = "<b>Address</b>: ${SDE.GasServiceLocation.LOCATIONDESCRIPTION}";
  var infoTemplate = new InfoTemplate("${SDE.GasServiceLocation.CU_ID}", content);

  featureLayer = new FeatureLayer("http://gisadev:6080/arcgis/rest/services/ISS_Inspections/FeatureServer/0",
        mode: FeatureLayer.MODE_ONDEMAND,
        infoTemplate: infoTemplate,
        outFields: ["*"]

  featureLayer.on("selection-complete", createListForAssignment);
  //featureLayer.on("selection-clear", function () {
  //    dom.byId('messages').innerHTML = "<i>No Selected Fields</i>";

  var myGeocoders = [{
      url: locatorUrl,
      name: "SDE.AddressLocator_Comp"
  geocoder = new Geocoder({
      map: map,
      autoComplete: true,
      arcgisGeocoder: false,
      geocoders: myGeocoders,
      value: "",
      zoomScale: 1200

  }, "search");

  on(dom.byId("selectFieldsButton"), "click", function () {
  on(dom.byId("clearSelectionButton"), "click", function () {
  on(dom.byId("BaseMapToggle"), "click", ChangeBaseMap);
  //on(dom.byId("assignCrew"), "click", AssignInspectionCrew);

  function initSelectToolbar(event) {
      selectionToolbar = new Draw(event.map);
      var selectQuery = new Query();

      on(selectionToolbar, "DrawEnd", function (geometry) {
          selectQuery.geometry = geometry;
  function ChangeBaseMap() {
      if (currentBaseMap == "Streets") {
          currentBaseMap = "Aerials";

      else if (currentBaseMap == "Aerials") {
          currentBaseMap = "Streets";
  function createListForAssignment(event) {
      document.getElementById("AssignFrm").style.visibility = "visible";
      document.getElementById("AssignBTN").style.visibility = "visible";

      arrayUtil.forEach(event.features, function (feature, index) {
  function assign() {
  if (document.getElementById('Jordan').checked) {
    x = document.getElementById('Jordan').value;
    for (var i = 0; i < selectedPoints.length; i++) {
        selectedPoints[i].attributes.ASSIGNED_TO = x;
  else {
    y = document.getElementById('Trenton').value;
  • What error are you getting in the console?
    – ianbroad
    Commented Sep 9, 2014 at 1:28

2 Answers 2


Welcome to GIS Stack Exchange. Thanks for sharing your code - a suggestion is to simplify this and only include the relevant parts of your code (rather than the entire application). In this case, that might be just the loop where you're trying to edit the feature layer.

Have you looked at applyEdits in the feature layer help file? This is one way to edit features programatically, and would be suitable for use within a JS loop.


In my application, the user selects features using the one of the Draw tools, then clicks a button that runs this function to apply changes that were set in several combo boxes

function applyChanges() {
    //extraneous code to check for various conditions omitted

    array.forEach(featureSet, function (feature) {
        feature.attributes.Priority = registry.byId('cboPriority').get("value");
        feature.attributes.Management = registry.byId('cboManagement').get("value");
        feature.attributes.Criteria1 = registry.byId('cboCriteria1').get("value");
        feature.attributes.Criteria2 = registry.byId('cboCriteria2').get("value");
        feature.attributes.Criteria3 = registry.byId('cboCriteria3').get("value");

    layerFeatureLayer.applyEdits(null, featureSet, null, function () { console.log("Success!"); }, function (error) { console.log(error); });

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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