I can currently use the JS API v4.3 to create (new) a FeatureLayer object, load it, query it and perform updates on it using applyEdits. But this only seems to work on data stored in a feature class accessed via a REST endpoint (url). I also need to be able to access non-feature classes (i.e. regular tables in the database) preferably in the same manner. Currently if I try to do this I get an error on the load() of the FeatureLayer - "The table feature service type is not yet supported".
Is there some other class or mechanism I should be using in order to accomplish this task? The REST service has both Layers AND Tables and I need to be able to access and update both but I have been unable to find a solution for the Tables. Please let me know if this is possible and how best to approach this problem. Thank you!
Are you using featureLayer.applyEdits from the JavaScript API?
You should be able to use the REST API to do anything that you've done before, you may just have to manually make the requests, ie use esri/Request to make an applyEdits request directly to ArcGIS REST API. The underlying REST API hasn't changed, just the JavaScript interface.
I'm not totally clear on the distinction between feature classes and tables in the DB, but as long as a table is part of a feature service, you should be able to edit it using the REST API.
Thank for the reply Thomas. A few things here : First I'm very new to Esri/Gis and this JS API so please bear with me...
The ArcGIS REST Service serves currently serves up both Layers and Tables. I'm not entirely clear on the distinction either but I was under the impression the Layers were the 'feature classes' and the Tables were just standard (maybe non spatial?) tables... different than what a feature layer would be.
That being said for a Layer/FeatureClass I can do this (pseudo code):
var fLayer = new FeatureLayer({ url: myRestUrl });
fLayer.load().then(function () { .. do stuff here with results .. });
I can then do querys on this fLayer and perform applyEdits, etc.
But if I try the same approach to the 'standard' Tables it just throws the error I posted above on the fLayer.load() function. "The table feature service type is not yet supported" So in that since I am unable to query it and use eatureLayer.applyEdits since the fLayer never 'loads'.
Could you possibly give an example of how "to manually make the requests, ie use esri/Request to make an applyEdits request directly to ArcGIS REST API"? Of course I need to query for the data first as well. I'm assuming that can be done using the esri/Request as well?
Thank you again!
Brief background: a feature service/feature server can have an arbitrary number of layers or tables. Each layer/table has an index. You could query a layer/table on a feature service with a URL like this:
https://<domain>.esri.com/arcgis/rest/services/<feature service name>/FeatureServer/<layer/table idx>/query
REST API ref: ArcGIS REST API
Here's an example of how to do this via esriRequest:
esriRequest('<feature layer/table url>/query',{
query: {
where:"1=1", // sql clause, 1=1 means every feature
outFields:'*', // attribute fields to return
token: <user token>, // token
f:"json" // format
},
}).then(function(r){
if (r.features){
console.log(r.features);
} else {
console.log('No Features Returned.');
}
});
Here's an example of how you might use applyEdits:
https://<domain>.esri.com/arcgis/rest/services/<feature service name>/FeatureServer/<layer/table idx>/applyEdits
REST API ref: ArcGIS REST API
esriRequest('<feature layer/table url>/applyEdits',{
query: {
method: 'post', // POST request
adds: [ // this is an array of JSON from a graphic:
// you can get it using graphic.toJSON()
// or construct the JSON manually
// if the 'layer' is a table, do not specify
// a geometry
{
geometry: {"x" : -118.15, "y" : 33.80},
attributes: {
OWNER: "Joe Smith",
VALUE: 94820.37,
APPROVED: true,
LASTUPDATE: 1227663551096
}
},
{
... // feature to add #2
}
],
updates: [
{
... // same as adds, except you must include an
// object id, which is the unique id for this feature
// the object id field can be anything, but it's usually
// objectId or OBJECTID, you can check on the layer
}
],
deletes: <object1, objectid2, ...>, // deletes just needs a comma-delimited
// list of object ids
token: <user token>, // token
f:"json" // format
},
}).then(function(r){
console.log(r);
});
Technically you should also be able to fetch all layers/table on a feature server using /query on the root feature server URL (see: ArcGIS REST API ). But I've never been able to get that to work.