Editing a non-spatial table?

2065
5
Jump to solution
12-04-2013 06:20 AM
ionarawilson1
Occasional Contributor III
Does anybody have an example of editing a non-spatial table? Thank you!!!
0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Frequent Contributor
It's the same as I would do saving to a regular FeatureService.

I have a module that is used to perform all my saves/syncs

I put together a more comprehensive example of how I use perform saves/updates.

// using the historyutil.js module I posted earlier
var Service = declare([], {
 constructor: function(options) {
  this.options = options;
  this.map = this.options.map;
  // the options will have a URL to the
  // non-spatial table in my FeatureService
  // for recording the history of my edits
  this.editHistory = new HisotryUtil(this.options);
  // this is the actual layer with spatial features that
  // I will edit.
  this.editLayer = this.map.getLayer('defectsLayer');
 },
 
 save: function(name, adds, updates) {
  var deferred = new Deferred();
  var self = this;
  // first edit my spatial layer
  // NOTE - Deletes not allowed in app, but you could track that if
  // needed.
  this.editLayer.applyEdits(adds, updates, null, function (results) {
    // when spatial table successfully edited, send same
    // edits to history table using the HistoryUtil
    // module in previous post.
    self.editHistory.save(adds, filterUpdate(updates));
    self.editLayer.refresh(); // quick refresh
    // I don't to see if
    // history update finished because I don't care.
    // History is a backend thing, not app related.
    // In production I would check if this failed and
    // log it somewhere else.
    // Now I can resolve my results.
    deferred.resolve(results);
   }, function (error) {
    deferred.reject(error);
   });
  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) {
  // helper function to see if the status changed
  return !statsMatch(item.attributes, 'PreviousStatus', 'DefectStatus');
 });
}

return Service;

View solution in original post

0 Kudos
5 Replies
ReneRubalcava
Frequent Contributor
Is this table published on your ArcGIS Server?
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.

For example, in one app, I need to update a history table when ever some features get added/updated/deleted.
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.

define([
  'dojo/_base/declare',
  'esri/layers/FeatureLayer'
], function(
  declare,
  FeatureLayer
) {
  'use strict';
  return declare(null, {

    constructor: function(options) {
      this.historyLayer = new FeatureLayer(options.settings.defectHistory);
    },

    save: function(adds, updates, deletes) {
      return this.historyLayer.applyEdits(adds, updates, deletes);
    }
  });

});
0 Kudos
ionarawilson1
Occasional Contributor III
Hi Rene,

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!!!
0 Kudos
ionarawilson1
Occasional Contributor III
Rene, can you please share a little bit more of your code? Thanks
0 Kudos
ReneRubalcava
Frequent Contributor
It's the same as I would do saving to a regular FeatureService.

I have a module that is used to perform all my saves/syncs

I put together a more comprehensive example of how I use perform saves/updates.

// using the historyutil.js module I posted earlier
var Service = declare([], {
 constructor: function(options) {
  this.options = options;
  this.map = this.options.map;
  // the options will have a URL to the
  // non-spatial table in my FeatureService
  // for recording the history of my edits
  this.editHistory = new HisotryUtil(this.options);
  // this is the actual layer with spatial features that
  // I will edit.
  this.editLayer = this.map.getLayer('defectsLayer');
 },
 
 save: function(name, adds, updates) {
  var deferred = new Deferred();
  var self = this;
  // first edit my spatial layer
  // NOTE - Deletes not allowed in app, but you could track that if
  // needed.
  this.editLayer.applyEdits(adds, updates, null, function (results) {
    // when spatial table successfully edited, send same
    // edits to history table using the HistoryUtil
    // module in previous post.
    self.editHistory.save(adds, filterUpdate(updates));
    self.editLayer.refresh(); // quick refresh
    // I don't to see if
    // history update finished because I don't care.
    // History is a backend thing, not app related.
    // In production I would check if this failed and
    // log it somewhere else.
    // Now I can resolve my results.
    deferred.resolve(results);
   }, function (error) {
    deferred.reject(error);
   });
  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) {
  // helper function to see if the status changed
  return !statsMatch(item.attributes, 'PreviousStatus', 'DefectStatus');
 });
}

return Service;
0 Kudos
ionarawilson1
Occasional Contributor III
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!!!
0 Kudos