<?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: When using a Feature Layer, applyedits fires multiple times in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/when-using-a-feature-layer-applyedits-fires/m-p/301748#M27687</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I can see one problem. You defined the event handlers for yesAddButton and noAddButton inside the callback function of draw-end event. So every time when you draw a graphic, yesAddButton and noAddButton event handlers will be defined one time. It will end up that if you draw two graphics, applyEdits will be triggered twice; three graphics, call applyEdits three times, and so on.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Move below code outside of dojo.connect(drawToolbar, "onDrawEnd", function(geometry) {...}); block. It should clear the issue.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp; dojo.connect(yesAddButton, "onclick", function () { &amp;nbsp;&amp;nbsp;&amp;nbsp; dijit.byId("addFeatureDialog").hide(); &amp;nbsp;&amp;nbsp;&amp;nbsp; //when features are added - add them to the undo manager&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; selectedTemplate.featureLayer.applyEdits([newGraphic], null, null, function() { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var operation = new esri.dijit.editing.Add({ &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; featureLayer: selectedTemplate.featureLayer, &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; addedGraphics: [newGraphic] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; undoManager.add(operation);&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; checkUI(); &amp;nbsp;&amp;nbsp;&amp;nbsp; }); &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; }); &amp;nbsp; dojo.connect(noAddButton, "onclick", function () { &amp;nbsp;&amp;nbsp;&amp;nbsp; dijit.byId("addFeatureDialog").hide(); &amp;nbsp; });&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 17 Oct 2013 19:07:40 GMT</pubDate>
    <dc:creator>JasonZou</dc:creator>
    <dc:date>2013-10-17T19:07:40Z</dc:date>
    <item>
      <title>When using a Feature Layer, applyedits fires multiple times</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/when-using-a-feature-layer-applyedits-fires/m-p/301745#M27684</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm using a feature layer that is editable and when a new feature is added, I'd like to prompt the user with a dijit dialog box to confirm they want to add the new feature to the database.&amp;nbsp; This works fine when only one feature is added during a editing session, but if more than one is created, the applyedits function is fired multiple times and all the features in the editing session are duplicated with each new feature.&amp;nbsp; I used Firebug to see the multiple POST events are firing when I think there should only be one call to applyedits.&amp;nbsp; The duplicated features will also have an ObjectID this is out of sequence with the others.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've tried omitting the dialog box and it work as expected.&amp;nbsp; I've tried clearing the default map graphics layer and the feature layer with no success.&amp;nbsp; Where are they hiding!&amp;nbsp; I've also modified an editing example from Esri and ran into the same problem.&amp;nbsp; Any advice is appreciated!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Oct 2013 18:07:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/when-using-a-feature-layer-applyedits-fires/m-p/301745#M27684</guid>
      <dc:creator>BethManghi</dc:creator>
      <dc:date>2013-10-17T18:07:00Z</dc:date>
    </item>
    <item>
      <title>Re: When using a Feature Layer, applyedits fires multiple times</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/when-using-a-feature-layer-applyedits-fires/m-p/301746#M27685</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;More than likely, applyEdits is triggered multiple times. Without looking at the code, it's hard to tell how multiple triggers are defined. Can you post your code? It would be great if you can post your code in &lt;/SPAN&gt;&lt;A href="http://jsfiddle.net/"&gt;jsFiddle&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Oct 2013 18:38:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/when-using-a-feature-layer-applyedits-fires/m-p/301746#M27685</guid>
      <dc:creator>JasonZou</dc:creator>
      <dc:date>2013-10-17T18:38:37Z</dc:date>
    </item>
    <item>
      <title>Re: When using a Feature Layer, applyedits fires multiple times</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/when-using-a-feature-layer-applyedits-fires/m-p/301747#M27686</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here's what I added to the Editor with undo redo example from Esri&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The dijit dialog:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

&amp;lt;div id="addFeatureDialog" data-dojo-type="dijit.Dialog" style="display: none;" title="Add Feature to Database?"&amp;gt;
&amp;nbsp; &amp;lt;p&amp;gt;Do you want to add this location to the database?&amp;lt;/p&amp;gt;
&amp;nbsp; &amp;lt;div id="yesNoDiv"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;div id="yesAddButton" data-dojo-type="dijit.form.Button" &amp;gt;Yes&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;div id="noAddButton" data-dojo-type="dijit.form.Button" &amp;gt;No&amp;lt;/div&amp;gt;
&amp;nbsp; &amp;lt;/div&amp;gt; &amp;lt;!-- end #yesNoDiv --&amp;gt;
&amp;lt;/div&amp;gt; &amp;lt;!-- end #addFeatureDialog --&amp;gt;

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then displayed the dialog just before applyEdits is called (at line 22 in the example):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
//once the geometry is drawn - call applyEdits to update the feature service with the new geometry
dojo.connect(drawToolbar, "onDrawEnd", function(geometry) {
&amp;nbsp; drawToolbar.deactivate();
&amp;nbsp; var dialog = dijit.byId("addFeatureDialog");
&amp;nbsp; var newAttributes = dojo.mixin({},selectedTemplate.template.prototype.attributes);
&amp;nbsp; var newGraphic = new esri.Graphic(geometry,null,newAttributes);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp; dialog.style.display = "block";
&amp;nbsp; dialog.closeButtonNode.style.display = "none";
&amp;nbsp; dialog.show();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp; dojo.connect(yesAddButton, "onclick", function () {
&amp;nbsp;&amp;nbsp;&amp;nbsp; dijit.byId("addFeatureDialog").hide();
&amp;nbsp;&amp;nbsp;&amp;nbsp; //when features are added - add them to the undo manager&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; selectedTemplate.featureLayer.applyEdits([newGraphic], null, null, function() {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var operation = new esri.dijit.editing.Add({
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; featureLayer: selectedTemplate.featureLayer,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; addedGraphics: [newGraphic]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; undoManager.add(operation);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; checkUI();
&amp;nbsp;&amp;nbsp;&amp;nbsp; });
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp; });
&amp;nbsp; dojo.connect(noAddButton, "onclick", function () {
&amp;nbsp;&amp;nbsp;&amp;nbsp; dijit.byId("addFeatureDialog").hide();
&amp;nbsp; });
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
});
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:28:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/when-using-a-feature-layer-applyedits-fires/m-p/301747#M27686</guid>
      <dc:creator>BethManghi</dc:creator>
      <dc:date>2021-12-11T14:28:35Z</dc:date>
    </item>
    <item>
      <title>Re: When using a Feature Layer, applyedits fires multiple times</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/when-using-a-feature-layer-applyedits-fires/m-p/301748#M27687</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I can see one problem. You defined the event handlers for yesAddButton and noAddButton inside the callback function of draw-end event. So every time when you draw a graphic, yesAddButton and noAddButton event handlers will be defined one time. It will end up that if you draw two graphics, applyEdits will be triggered twice; three graphics, call applyEdits three times, and so on.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Move below code outside of dojo.connect(drawToolbar, "onDrawEnd", function(geometry) {...}); block. It should clear the issue.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp; dojo.connect(yesAddButton, "onclick", function () { &amp;nbsp;&amp;nbsp;&amp;nbsp; dijit.byId("addFeatureDialog").hide(); &amp;nbsp;&amp;nbsp;&amp;nbsp; //when features are added - add them to the undo manager&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; selectedTemplate.featureLayer.applyEdits([newGraphic], null, null, function() { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var operation = new esri.dijit.editing.Add({ &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; featureLayer: selectedTemplate.featureLayer, &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; addedGraphics: [newGraphic] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; undoManager.add(operation);&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; checkUI(); &amp;nbsp;&amp;nbsp;&amp;nbsp; }); &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; }); &amp;nbsp; dojo.connect(noAddButton, "onclick", function () { &amp;nbsp;&amp;nbsp;&amp;nbsp; dijit.byId("addFeatureDialog").hide(); &amp;nbsp; });&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Oct 2013 19:07:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/when-using-a-feature-layer-applyedits-fires/m-p/301748#M27687</guid>
      <dc:creator>JasonZou</dc:creator>
      <dc:date>2013-10-17T19:07:40Z</dc:date>
    </item>
    <item>
      <title>Re: When using a Feature Layer, applyedits fires multiple times</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/when-using-a-feature-layer-applyedits-fires/m-p/301749#M27688</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you, zj_zou!&amp;nbsp; Your advice did the trick!&amp;nbsp; I moved the yesAddButton and noAddButton event handlers to a different location in the code so they're only defined once.&amp;nbsp; Now, my original application is working as expected!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Oct 2013 13:21:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/when-using-a-feature-layer-applyedits-fires/m-p/301749#M27688</guid>
      <dc:creator>BethManghi</dc:creator>
      <dc:date>2013-10-21T13:21:07Z</dc:date>
    </item>
  </channel>
</rss>

