<?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: Editing a non-spatial table? in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/editing-a-non-spatial-table/m-p/439259#M40479</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It's the same as I would do saving to a regular FeatureService.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a module that is used to perform all my saves/syncs&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I put together a more comprehensive example of how I use perform saves/updates.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

// using the historyutil.js module I posted earlier
var Service = declare([], {
 constructor: function(options) {
&amp;nbsp; this.options = options;
&amp;nbsp; this.map = this.options.map;
&amp;nbsp; // the options will have a URL to the
&amp;nbsp; // non-spatial table in my FeatureService
&amp;nbsp; // for recording the history of my edits
&amp;nbsp; this.editHistory = new HisotryUtil(this.options);
&amp;nbsp; // this is the actual layer with spatial features that
&amp;nbsp; // I will edit.
&amp;nbsp; this.editLayer = this.map.getLayer('defectsLayer');
 },
 
 save: function(name, adds, updates) {
&amp;nbsp; var deferred = new Deferred();
&amp;nbsp; var self = this;
&amp;nbsp; // first edit my spatial layer
&amp;nbsp; // NOTE - Deletes not allowed in app, but you could track that if
&amp;nbsp; // needed.
&amp;nbsp; this.editLayer.applyEdits(adds, updates, null, function (results) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; // when spatial table successfully edited, send same
&amp;nbsp;&amp;nbsp;&amp;nbsp; // edits to history table using the HistoryUtil
&amp;nbsp;&amp;nbsp;&amp;nbsp; // module in previous post.
&amp;nbsp;&amp;nbsp;&amp;nbsp; self.editHistory.save(adds, filterUpdate(updates));
&amp;nbsp;&amp;nbsp;&amp;nbsp; self.editLayer.refresh(); // quick refresh
&amp;nbsp;&amp;nbsp;&amp;nbsp; // I don't to see if
&amp;nbsp;&amp;nbsp;&amp;nbsp; // history update finished because I don't care.
&amp;nbsp;&amp;nbsp;&amp;nbsp; // History is a backend thing, not app related.
&amp;nbsp;&amp;nbsp;&amp;nbsp; // In production I would check if this failed and
&amp;nbsp;&amp;nbsp;&amp;nbsp; // log it somewhere else.
&amp;nbsp;&amp;nbsp;&amp;nbsp; // Now I can resolve my results.
&amp;nbsp;&amp;nbsp;&amp;nbsp; deferred.resolve(results);
&amp;nbsp;&amp;nbsp; }, function (error) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; deferred.reject(error);
&amp;nbsp;&amp;nbsp; });
&amp;nbsp; return deferred.promise;
 },
});

// This function finds out if two field
// values are identical
function statsMatch(obj, field1, field2) {
 return obj[field1] === obj[field2];
}

// If I'm doing an update of data, I just track status changes.
// So I filter out any features where the status did NOT change.
function filterUpdate(items) {
 return arrayUtil.filter(items, function(item) {
&amp;nbsp; // helper function to see if the status changed
&amp;nbsp; return !statsMatch(item.attributes, 'PreviousStatus', 'DefectStatus');
 });
}

return Service;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 19:39:18 GMT</pubDate>
    <dc:creator>ReneRubalcava</dc:creator>
    <dc:date>2021-12-11T19:39:18Z</dc:date>
    <item>
      <title>Editing a non-spatial table?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/editing-a-non-spatial-table/m-p/439255#M40475</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Does anybody have an example of editing a non-spatial table? Thank you!!!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Dec 2013 14:20:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/editing-a-non-spatial-table/m-p/439255#M40475</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2013-12-04T14:20:45Z</dc:date>
    </item>
    <item>
      <title>Re: Editing a non-spatial table?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/editing-a-non-spatial-table/m-p/439256#M40476</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Is this table published on your ArcGIS Server?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If so, I just publish it in a FeatureService with related Features and load the table as a FeatureLayer and apply edits as needed. It's worked great for me so far.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example, in one app, I need to update a history table when ever some features get added/updated/deleted.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;So I have this utility module that simply accepts arrays of graphics with empty geometries (or not, it doesn't matter) with the updated information and updates the table as a FeatureLayer. The CRUD functions don't care if it has a geometry or not.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
define([
&amp;nbsp; 'dojo/_base/declare',
&amp;nbsp; 'esri/layers/FeatureLayer'
], function(
&amp;nbsp; declare,
&amp;nbsp; FeatureLayer
) {
&amp;nbsp; 'use strict';
&amp;nbsp; return declare(null, {

&amp;nbsp;&amp;nbsp;&amp;nbsp; constructor: function(options) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.historyLayer = new FeatureLayer(options.settings.defectHistory);
&amp;nbsp;&amp;nbsp;&amp;nbsp; },

&amp;nbsp;&amp;nbsp;&amp;nbsp; save: function(adds, updates, deletes) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return this.historyLayer.applyEdits(adds, updates, deletes);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp; });

});
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:39:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/editing-a-non-spatial-table/m-p/439256#M40476</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2021-12-11T19:39:15Z</dc:date>
    </item>
    <item>
      <title>Re: Editing a non-spatial table?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/editing-a-non-spatial-table/m-p/439257#M40477</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Rene,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, it is in my server published as a feature service. Would you be so kind to share your code with me? Thank you so much!!!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Dec 2013 17:38:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/editing-a-non-spatial-table/m-p/439257#M40477</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2013-12-04T17:38:07Z</dc:date>
    </item>
    <item>
      <title>Re: Editing a non-spatial table?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/editing-a-non-spatial-table/m-p/439258#M40478</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Rene, can you please share a little bit more of your code? Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Dec 2013 13:01:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/editing-a-non-spatial-table/m-p/439258#M40478</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2013-12-06T13:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: Editing a non-spatial table?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/editing-a-non-spatial-table/m-p/439259#M40479</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It's the same as I would do saving to a regular FeatureService.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a module that is used to perform all my saves/syncs&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I put together a more comprehensive example of how I use perform saves/updates.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

// using the historyutil.js module I posted earlier
var Service = declare([], {
 constructor: function(options) {
&amp;nbsp; this.options = options;
&amp;nbsp; this.map = this.options.map;
&amp;nbsp; // the options will have a URL to the
&amp;nbsp; // non-spatial table in my FeatureService
&amp;nbsp; // for recording the history of my edits
&amp;nbsp; this.editHistory = new HisotryUtil(this.options);
&amp;nbsp; // this is the actual layer with spatial features that
&amp;nbsp; // I will edit.
&amp;nbsp; this.editLayer = this.map.getLayer('defectsLayer');
 },
 
 save: function(name, adds, updates) {
&amp;nbsp; var deferred = new Deferred();
&amp;nbsp; var self = this;
&amp;nbsp; // first edit my spatial layer
&amp;nbsp; // NOTE - Deletes not allowed in app, but you could track that if
&amp;nbsp; // needed.
&amp;nbsp; this.editLayer.applyEdits(adds, updates, null, function (results) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; // when spatial table successfully edited, send same
&amp;nbsp;&amp;nbsp;&amp;nbsp; // edits to history table using the HistoryUtil
&amp;nbsp;&amp;nbsp;&amp;nbsp; // module in previous post.
&amp;nbsp;&amp;nbsp;&amp;nbsp; self.editHistory.save(adds, filterUpdate(updates));
&amp;nbsp;&amp;nbsp;&amp;nbsp; self.editLayer.refresh(); // quick refresh
&amp;nbsp;&amp;nbsp;&amp;nbsp; // I don't to see if
&amp;nbsp;&amp;nbsp;&amp;nbsp; // history update finished because I don't care.
&amp;nbsp;&amp;nbsp;&amp;nbsp; // History is a backend thing, not app related.
&amp;nbsp;&amp;nbsp;&amp;nbsp; // In production I would check if this failed and
&amp;nbsp;&amp;nbsp;&amp;nbsp; // log it somewhere else.
&amp;nbsp;&amp;nbsp;&amp;nbsp; // Now I can resolve my results.
&amp;nbsp;&amp;nbsp;&amp;nbsp; deferred.resolve(results);
&amp;nbsp;&amp;nbsp; }, function (error) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; deferred.reject(error);
&amp;nbsp;&amp;nbsp; });
&amp;nbsp; return deferred.promise;
 },
});

// This function finds out if two field
// values are identical
function statsMatch(obj, field1, field2) {
 return obj[field1] === obj[field2];
}

// If I'm doing an update of data, I just track status changes.
// So I filter out any features where the status did NOT change.
function filterUpdate(items) {
 return arrayUtil.filter(items, function(item) {
&amp;nbsp; // helper function to see if the status changed
&amp;nbsp; return !statsMatch(item.attributes, 'PreviousStatus', 'DefectStatus');
 });
}

return Service;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:39:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/editing-a-non-spatial-table/m-p/439259#M40479</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2021-12-11T19:39:18Z</dc:date>
    </item>
    <item>
      <title>Re: Editing a non-spatial table?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/editing-a-non-spatial-table/m-p/439260#M40480</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you so much Rene! I ended up doing it in Flex, which I am more familiar. I am a newbie in Javascript but really want to learn more. Thanks again!!!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Dec 2013 15:20:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/editing-a-non-spatial-table/m-p/439260#M40480</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2013-12-13T15:20:21Z</dc:date>
    </item>
  </channel>
</rss>

