<?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 Inject value during editing workflow in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/inject-value-during-editing-workflow/m-p/1631291#M87343</link>
    <description>&lt;P&gt;I am working on an application designed for users to make some simple feature layer edits. The users have full add/update/delete privileges. Another portion of the application generates a string value. I would like to have this value automatically included as the value of one of the fields whenever a user makes an edit. I don't care if the user sees this value or not, but the user should not be able to change it.&lt;/P&gt;&lt;P&gt;In a similar application, I was able to do this using&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/6522"&gt;@JoelBennett&lt;/a&gt;'s solution from &lt;A href="https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/preset-value-in-editor-widget-in-a-js-app-using/td-p/1352220" target="_self"&gt;this post&lt;/A&gt;.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;editorVM.watch(['state', 'featureFormViewModel.feature', 'featureFormViewModel.state'], () =&amp;gt; {
  if (editorVM.state == 'creating-features' &amp;amp;&amp;amp; editorVM.featureFormViewModel.feature &amp;amp;&amp;amp; editorVM.featureFormViewModel.state == 'ready') { 
    window.setTimeout(function() {
      editorVM.featureFormViewModel.setValue('PhoneNumber', "999.999.999")
    }, 200);
  }  
});&lt;/LI-CODE&gt;&lt;P&gt;But there are two complications for this application.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;This time I am using the Editor Component, not the Editor Widget, and the widget view model does not appear to be accessible through the Component.&lt;/LI&gt;&lt;LI&gt;This application also has a FeatureTable Component that is editable and I also want the value injected when editing is done through the table.&lt;/LI&gt;&lt;/OL&gt;&lt;P data-unlink="true"&gt;Feature layers have the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#event-edits" target="_self"&gt;edits event&lt;/A&gt; that can be watched for, but it happens after the applyEdits() method completes. If I try to use applyEdits() inside this event, I will create an infinite loop. The code I want to write would intercept before the applyEdits() method is called, inject my value into the attributes and then proceed saving the edits.&lt;/P&gt;&lt;P data-unlink="true"&gt;&lt;STRONG&gt;Goal:&lt;/STRONG&gt; Automatically add string variable to the attributes of a Feature Layer whenever it is edited in an application.&lt;/P&gt;&lt;P data-unlink="true"&gt;&lt;STRONG&gt;Restrictions:&lt;/STRONG&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Users cannot alter this value.&lt;/LI&gt;&lt;LI&gt;Must work with both Editor and FeatureTable Components.&lt;/LI&gt;&lt;/OL&gt;</description>
    <pubDate>Tue, 08 Jul 2025 19:51:47 GMT</pubDate>
    <dc:creator>JeffreyThompson2</dc:creator>
    <dc:date>2025-07-08T19:51:47Z</dc:date>
    <item>
      <title>Inject value during editing workflow</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/inject-value-during-editing-workflow/m-p/1631291#M87343</link>
      <description>&lt;P&gt;I am working on an application designed for users to make some simple feature layer edits. The users have full add/update/delete privileges. Another portion of the application generates a string value. I would like to have this value automatically included as the value of one of the fields whenever a user makes an edit. I don't care if the user sees this value or not, but the user should not be able to change it.&lt;/P&gt;&lt;P&gt;In a similar application, I was able to do this using&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/6522"&gt;@JoelBennett&lt;/a&gt;'s solution from &lt;A href="https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/preset-value-in-editor-widget-in-a-js-app-using/td-p/1352220" target="_self"&gt;this post&lt;/A&gt;.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;editorVM.watch(['state', 'featureFormViewModel.feature', 'featureFormViewModel.state'], () =&amp;gt; {
  if (editorVM.state == 'creating-features' &amp;amp;&amp;amp; editorVM.featureFormViewModel.feature &amp;amp;&amp;amp; editorVM.featureFormViewModel.state == 'ready') { 
    window.setTimeout(function() {
      editorVM.featureFormViewModel.setValue('PhoneNumber', "999.999.999")
    }, 200);
  }  
});&lt;/LI-CODE&gt;&lt;P&gt;But there are two complications for this application.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;This time I am using the Editor Component, not the Editor Widget, and the widget view model does not appear to be accessible through the Component.&lt;/LI&gt;&lt;LI&gt;This application also has a FeatureTable Component that is editable and I also want the value injected when editing is done through the table.&lt;/LI&gt;&lt;/OL&gt;&lt;P data-unlink="true"&gt;Feature layers have the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#event-edits" target="_self"&gt;edits event&lt;/A&gt; that can be watched for, but it happens after the applyEdits() method completes. If I try to use applyEdits() inside this event, I will create an infinite loop. The code I want to write would intercept before the applyEdits() method is called, inject my value into the attributes and then proceed saving the edits.&lt;/P&gt;&lt;P data-unlink="true"&gt;&lt;STRONG&gt;Goal:&lt;/STRONG&gt; Automatically add string variable to the attributes of a Feature Layer whenever it is edited in an application.&lt;/P&gt;&lt;P data-unlink="true"&gt;&lt;STRONG&gt;Restrictions:&lt;/STRONG&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Users cannot alter this value.&lt;/LI&gt;&lt;LI&gt;Must work with both Editor and FeatureTable Components.&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Tue, 08 Jul 2025 19:51:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/inject-value-during-editing-workflow/m-p/1631291#M87343</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2025-07-08T19:51:47Z</dc:date>
    </item>
    <item>
      <title>Re: Inject value during editing workflow</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/inject-value-during-editing-workflow/m-p/1631496#M87349</link>
      <description>&lt;P&gt;in terms of accessing the viewmodel for the widget I have found that it is seemingly possible via an undocumented property on the web components. I have implemented some additional logic to hook into some viewmodel events/properties on the Features Component.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function isWaitingForResult(element: HTMLArcgisFeaturesElement) {
return element.widget?.viewModel?.waitingForResult ?? false;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jul 2025 10:17:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/inject-value-during-editing-workflow/m-p/1631496#M87349</guid>
      <dc:creator>JonathanDawe_BAS</dc:creator>
      <dc:date>2025-07-09T10:17:43Z</dc:date>
    </item>
    <item>
      <title>Re: Inject value during editing workflow</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/inject-value-during-editing-workflow/m-p/1632264#M87367</link>
      <description>&lt;P&gt;An ugly but effective way to intercept a function call prior to its execution is to store a reference to the function, override it with your custom processing, and then call the original function at the end like so:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var featureLayer = new FeatureLayer({
	//etc
});

featureLayer.originalApplyEdits = featureLayer.applyEdits;

featureLayer.applyEdits = function(edits, options) {
	//do whatever you want to the "edits" object

	return this.originalApplyEdits.apply(this, arguments);
};&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 11 Jul 2025 00:24:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/inject-value-during-editing-workflow/m-p/1632264#M87367</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2025-07-11T00:24:39Z</dc:date>
    </item>
    <item>
      <title>Re: Inject value during editing workflow</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/inject-value-during-editing-workflow/m-p/1632525#M87375</link>
      <description>&lt;P&gt;Thanks,&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/6522"&gt;@JoelBennett&lt;/a&gt;. It works. For the record, here's what my completed function looks like.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt; featureLayer.originalApplyEdits = featureLayer.applyEdits
 featureLayer.applyEdits = function (edits, options) {
     console.log(edits, options)
     if (edits.addFeatures || edits.updateFeatures) {
         const features = edits.addFeatures || edits.updateFeatures
         features.forEach(feature =&amp;gt; {
             feature.attributes.attributeName = value
         })
     }

     return this.originalApplyEdits.apply(this, arguments)
 }&lt;/LI-CODE&gt;&lt;P&gt;I don't know if the if statement is necessary, I just threw it in case.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jul 2025 17:42:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/inject-value-during-editing-workflow/m-p/1632525#M87375</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2025-07-11T17:42:55Z</dc:date>
    </item>
  </channel>
</rss>

