<?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: Update a REST Service table from a Widget in Web AppBuilder Custom Widgets Questions</title>
    <link>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/update-a-rest-service-table-from-a-widget/m-p/863768#M12082</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Robert - Argghhh, I overlooked a really important detail. objs.lastupdated has to have an updated date to "update". It also had to be in epoch date format. I added the below with `&lt;SPAN style="background-color: #f6f6f6;"&gt;objs.lastupdated = Date.now();&lt;/SPAN&gt;` and it works fine now. Thanks for the assist:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;if (typeof proj_obj !== undefined) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; for (var j = 0; j &amp;lt; proj_obj.length; j++) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (s_proj == proj_type_obj&lt;J&gt;.subproject) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var objs = proj_type_obj&lt;J&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; objs.lastupdated = Date.now();&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; p_obj = objs;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;BR /&gt;&amp;nbsp; &amp;nbsp; }&lt;BR /&gt; }&lt;/J&gt;&lt;/J&gt;&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 20 Apr 2020 13:35:57 GMT</pubDate>
    <dc:creator>JustinBridwell2</dc:creator>
    <dc:date>2020-04-20T13:35:57Z</dc:date>
    <item>
      <title>Update a REST Service table from a Widget</title>
      <link>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/update-a-rest-service-table-from-a-widget/m-p/863764#M12078</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Suppose I have a WAB widget&amp;nbsp; (version 1.2) called TaskManager. Everytime a user clicks a button (triggering a click event) I want&amp;nbsp;to route it to&amp;nbsp;a function that will update a specific field called 'lastupdated' in a REST Service (FEATURE Service) table called SuprojectTypeTable, which looks like this in my widget config,json:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;"subprojectTaskTrackingURL": "&lt;A href="https://www.mywabapp.com/server/rest/services/.../FeatureServer" target="_blank"&gt;https://www.mywabapp.com/server/rest/services/.../FeatureServer&lt;/A&gt;",&lt;/P&gt;&lt;P&gt;"subprojectTypeTable": {&lt;BR /&gt;&amp;nbsp; "index": "5",&lt;BR /&gt;&amp;nbsp; "oid": "objectid",&lt;BR /&gt;&amp;nbsp; "subprojectName": "subproject",&lt;BR /&gt;&amp;nbsp; "projectType": "projecttype",&lt;BR /&gt;&amp;nbsp; "lastUpdated": "lastupdated"&lt;BR /&gt; },&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;This function will take one parameter, a subprojectName, so that it can update the specific row in the table that I want. It will also call a simple function that will get, format, and return the current date. This will be the value I want to plug into the 'lastupdated' field:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;currentDate: function(){
  var d =newDate();
  var month = d.getMonth()+1;
  var day = d.getDate();
  var currentD =((''+ month).length &amp;lt;2?'0':'')+ month +
  '/'+((''+ day).length &amp;lt;2?'0':'')+ day +'/'+ d.getFullYear();
  return currentD },&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;The REST Service can use apply edits and update features.&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;updateSubprojObj: function (s_proj) {&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; var new_date = thisWidget.currentDate();&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; var subproj = dijit.byId("subprojectSelect");&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;this.&lt;SPAN style="background-color: #f6f6f6;"&gt;subprojectTypeTable&lt;/SPAN&gt;.applyEdits(subproj, null, null, null, new_date, function (editResult) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; console.log(editResult);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; }, function (editError) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; console.log(editError);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; throw "Issue updating record in database."&lt;BR /&gt;&amp;nbsp; &amp;nbsp; }).then(function () {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; console.log('edit applied, updated item returned to grid')&lt;BR /&gt;&amp;nbsp; &amp;nbsp; });&lt;/P&gt;&lt;P&gt;},&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;The above does not work of course. What would be the best way to do this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 17:00:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/update-a-rest-service-table-from-a-widget/m-p/863764#M12078</guid>
      <dc:creator>JustinBridwell2</dc:creator>
      <dc:date>2021-12-12T17:00:44Z</dc:date>
    </item>
    <item>
      <title>Re: Update a REST Service table from a Widget</title>
      <link>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/update-a-rest-service-table-from-a-widget/m-p/863765#M12079</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Justin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; You need to look at what the applyEdits method is expecting (not what you are trying right now).&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://developers.arcgis.com/javascript/3/jsapi/featurelayer-amd.html#applyedits" title="https://developers.arcgis.com/javascript/3/jsapi/featurelayer-amd.html#applyedits"&gt;FeatureLayer | API Reference | ArcGIS API for JavaScript 3.32&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Manin thing it is expecting an object with an updates property containing an array of Graphics (not attributes, an actual graphic class with no geometry).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Apr 2020 23:32:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/update-a-rest-service-table-from-a-widget/m-p/863765#M12079</guid>
      <dc:creator>RobertScheitlin__GISP</dc:creator>
      <dc:date>2020-04-16T23:32:40Z</dc:date>
    </item>
    <item>
      <title>Re: Update a REST Service table from a Widget</title>
      <link>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/update-a-rest-service-table-from-a-widget/m-p/863766#M12080</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey Robert - I think I almost have this working. Its not throwing an error but it's not updating in the REST Service table. Here's&amp;nbsp;the function I&amp;nbsp;made that gets triggered in the updateItem (item) function when I call&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;thisWidget.updateSubprojObj(proj_type_obj, current_subproject);&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;The parameter `proj_type_obj` is an literally an array object containing the ObjectID (oid), subprojectName, subptojectType, and lastUpdated values for all items in the SubprojectType Table. subproject is just a dijit.byId("subprojectSelect") value that corresponds to the current subproject that I want to update:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;updateSubprojObj: function (proj_obj, s_proj) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; var p_obj = null;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; this.subprojectTypeTable = new FeatureLayer(subprojectTypeURL, {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; outFields: ["*"]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; });&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if (typeof proj_obj !== undefined) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (var j = 0; j &amp;lt; proj_obj.length; j++) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (s_proj == proj_type_obj&lt;J&gt;.subproject) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var objs = proj_type_obj&lt;J&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; p_obj = objs;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;BR /&gt;&amp;nbsp; &amp;nbsp; }&lt;BR /&gt;&amp;nbsp; &amp;nbsp; let updatedItem = Object.assign({}, p_obj);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; var updatedFeatureJson = updatedItem;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; var updatedFeature = new Graphic(null, null, updatedFeatureJson, null);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; this.subprojectTypeTable.applyEdits(null, [updatedFeature], null, function (editResult) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; console.log(editResult);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; }, function (editError) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; console.log(editError);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; throw "Issue updating record in database."&lt;BR /&gt;&amp;nbsp; &amp;nbsp; }).then(function () {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; console.log('edit applied, updated item returned to grid')&lt;BR /&gt;&amp;nbsp; &amp;nbsp; });&lt;BR /&gt; },&lt;/J&gt;&lt;/J&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Note: I didn't end up using the currentDate function to convert the date because it ended up requiring the epoch data format. Do you see anything wrong with this? The graphic array,&amp;nbsp;&lt;SPAN style="background-color: #f6f6f6;"&gt;updatedFeature looks like this when its getting plugged in:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;&lt;IMG __jive_id="489034" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/489034_pastedImage_8.png" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Apr 2020 02:30:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/update-a-rest-service-table-from-a-widget/m-p/863766#M12080</guid>
      <dc:creator>JustinBridwell2</dc:creator>
      <dc:date>2020-04-17T02:30:00Z</dc:date>
    </item>
    <item>
      <title>Re: Update a REST Service table from a Widget</title>
      <link>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/update-a-rest-service-table-from-a-widget/m-p/863767#M12081</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Justin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;Are there any error in your ArcGIS Server logs? Are you providing all required fields for this feature in the update object?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 Apr 2020 12:44:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/update-a-rest-service-table-from-a-widget/m-p/863767#M12081</guid>
      <dc:creator>RobertScheitlin__GISP</dc:creator>
      <dc:date>2020-04-20T12:44:42Z</dc:date>
    </item>
    <item>
      <title>Re: Update a REST Service table from a Widget</title>
      <link>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/update-a-rest-service-table-from-a-widget/m-p/863768#M12082</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Robert - Argghhh, I overlooked a really important detail. objs.lastupdated has to have an updated date to "update". It also had to be in epoch date format. I added the below with `&lt;SPAN style="background-color: #f6f6f6;"&gt;objs.lastupdated = Date.now();&lt;/SPAN&gt;` and it works fine now. Thanks for the assist:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;if (typeof proj_obj !== undefined) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; for (var j = 0; j &amp;lt; proj_obj.length; j++) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (s_proj == proj_type_obj&lt;J&gt;.subproject) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var objs = proj_type_obj&lt;J&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; objs.lastupdated = Date.now();&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; p_obj = objs;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;BR /&gt;&amp;nbsp; &amp;nbsp; }&lt;BR /&gt; }&lt;/J&gt;&lt;/J&gt;&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 Apr 2020 13:35:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/update-a-rest-service-table-from-a-widget/m-p/863768#M12082</guid>
      <dc:creator>JustinBridwell2</dc:creator>
      <dc:date>2020-04-20T13:35:57Z</dc:date>
    </item>
  </channel>
</rss>

