<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Help with updating attributes in FeatureLayer programmatically in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/help-with-updating-attributes-in-featurelayer/m-p/311246#M28627</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks you so much. This worked for me !!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 25 Nov 2016 21:54:38 GMT</pubDate>
    <dc:creator>satbirsingh</dc:creator>
    <dc:date>2016-11-25T21:54:38Z</dc:date>
    <item>
      <title>Help with updating attributes in FeatureLayer programmatically</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/help-with-updating-attributes-in-featurelayer/m-p/311243#M28624</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm looking for a little help as I learn JavaScript and the ArcGIS API.&amp;nbsp; I've managed to develop an app that leverages the templatePicker and Editor Widget.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&amp;nbsp; 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). &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;some of the applicable code follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
var map, polyFeatLayer

function init() {
&amp;nbsp;&amp;nbsp;&amp;nbsp; //... other code is in this function like the "onLayerAddResult" listener to initialize template picker/&amp;nbsp; editor widget, etc.
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; polyFeatLayer = new esri.layers.FeatureLayer("http://www......../FeatureServer/0", {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outFields: ,

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; id: "polyFeatLayerId"
&amp;nbsp;&amp;nbsp; });
&amp;nbsp;&amp;nbsp; // note: currently I have not added corresponding ArcGISDynamicMapServiceLayer

&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.connect(polyFeatLayer, "onEditsComplete", addResultsComplete);
&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.connect(polyFeatLayer, "onSelectionComplete", selectionComplete);
}

function addResultsComplete(addResults) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (addResults.length &amp;gt; 0) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; alert("got Result"); //so far this works
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var featLyr = map.getLayer("polyFeatLayerId");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var query = new esri.tasks.Query();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; query.where = "OBJECTID = '" + addResults[0].objectId + "'";
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; featLyr.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
}

function selectionComplete(features) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; alert("count: " + features.length);&amp;nbsp; // this is 0, unless I close the map.InfoWindow and manually (re)select a feature -- so this is my first problem area ... ???
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (features.length == 1) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var currentDate = new Date();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var dateString = ((currentDate.getMonth() + 1) + "/" + currentDate.getDate() + "/" + currentDate.getFullYear());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var fixedDate = new Date.parse(dateString);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var polyDesc = document.forms[0].polyDescriptionInput.value;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var feature = features[0];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; feature.attributes["DT_ADDED"] = fixedDate;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; feature.attributes["POLY_DESC"] = polyDesc;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; polyFeatLyr.applyEdits(null, [feature], null);&amp;nbsp;&amp;nbsp; //and this fails too!!! with a&amp;nbsp; "TypeError: that._currentGraphic is undefined"
//
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I really appreciate any help and direction with accomplishing this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;v/r, jason&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Nov 2010 13:33:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/help-with-updating-attributes-in-featurelayer/m-p/311243#M28624</guid>
      <dc:creator>JasonMielke</dc:creator>
      <dc:date>2010-11-10T13:33:04Z</dc:date>
    </item>
    <item>
      <title>Re: Help with updating attributes in FeatureLayer programmatically</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/help-with-updating-attributes-in-featurelayer/m-p/311244#M28625</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Figured this out a few days back and during that process realized I was way overcomplicating it.&amp;nbsp; I'm replying here with the thought that this may be helpful to someone in the future.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So here it is...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
var map, polyFeatLayer

function init() {
&amp;nbsp;&amp;nbsp;&amp;nbsp; //... other code is in this function like the "onLayerAddResult" listener to initialize template picker/&amp;nbsp; editor widget, etc.
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; polyFeatLayer = new esri.layers.FeatureLayer("http://www......../FeatureServer/0", {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outFields:&lt;LI&gt;,&lt;/LI&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; id: "polyFeatLayerId"
&amp;nbsp;&amp;nbsp; });

&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.connect(polyFeatLayer, "onEditsComplete", addResultsComplete);
}

function addResultsComplete(addResults) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (addResults.length &amp;gt; 0) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // this gets the corresponding graphic of the feature that was just added
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var graphic = polyFeatLayer.graphics[polyFeatLayer.graphics.length - 1];

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var currentDate = new Date();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var dateString = ((currentDate.getMonth() + 1) + "/" + currentDate.getDate() + "/" + currentDate.getFullYear());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var fixedDate = new Date.parse(dateString);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var polyDesc = document.forms[0].polyDescriptionInput.value;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; graphic.attributes["DT_ADDED"] = fixedDate;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; graphic.attributes["POLY_DESC"] = polyDesc;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; polyFeatLayer.applyEdits(null, [graphic], null);
&amp;nbsp;&amp;nbsp; }
}
//
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;jason&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:53:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/help-with-updating-attributes-in-featurelayer/m-p/311244#M28625</guid>
      <dc:creator>JasonMielke</dc:creator>
      <dc:date>2021-12-11T14:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: Help with updating attributes in FeatureLayer programmatically</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/help-with-updating-attributes-in-featurelayer/m-p/311245#M28626</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you so much for posting this solution. I've been struggling with this for days.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Mar 2011 18:30:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/help-with-updating-attributes-in-featurelayer/m-p/311245#M28626</guid>
      <dc:creator>JamesGonsoski</dc:creator>
      <dc:date>2011-03-22T18:30:05Z</dc:date>
    </item>
    <item>
      <title>Re: Help with updating attributes in FeatureLayer programmatically</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/help-with-updating-attributes-in-featurelayer/m-p/311246#M28627</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks you so much. This worked for me !!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Nov 2016 21:54:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/help-with-updating-attributes-in-featurelayer/m-p/311246#M28627</guid>
      <dc:creator>satbirsingh</dc:creator>
      <dc:date>2016-11-25T21:54:38Z</dc:date>
    </item>
    <item>
      <title>Re: Help with updating attributes in FeatureLayer programmatically</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/help-with-updating-attributes-in-featurelayer/m-p/311247#M28628</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;do you have real working demo ? I trying &amp;nbsp;a lot of difference examples no one doesn't work for me (&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 May 2017 14:03:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/help-with-updating-attributes-in-featurelayer/m-p/311247#M28628</guid>
      <dc:creator>AlexOliinyk</dc:creator>
      <dc:date>2017-05-16T14:03:21Z</dc:date>
    </item>
  </channel>
</rss>

