How do I Update a Table via a FeatureService?

1038
4
03-04-2014 06:31 AM
KeithFraley1
New Contributor II
I have my feature service all set up, I have my table served up in that feature service.  I can access via the rest explorer and do the update manually via "updateFeature" url.  what am I missing or is there a better way?

What is the best way to do this in javascript.  I keep getting a 405 error when I try and execute using dojo.xhrPost

var xhrArgs = {
      url: "http://url/FeatureServer/3/updateFeatures",
      postData: attributes),
      handleAs: "json",
      load: function(data){
        console.log("Message posted.");
      },
      error: function(error){
        console.log("Message posted.");
      }
    }
    console.log("Message being posted.");
    var deferred = dojo.xhrPost(xhrArgs);
  }
0 Kudos
4 Replies
JonathanUihlein
Esri Regular Contributor
Hi Keith!

Some documentation here:
https://developers.arcgis.com/javascript/jshelp/inside_feature_layers.html

The tutorial links at the bottom of that document are what you are looking for.
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Hi Keith,

I've never used dojo.xhrPost, but below is an example using XMLHttpRequest:

function addFeatures() {
    addFeaturesUrl = 'http://server/arcgis/rest/services/ClosedRoadsAddress/FeatureServer/2/addFeatures?features='
    addAttributesUrl1 = '[{"attributes":{"Address":"'100 Main St'"}}]'
    
    var obj1 = encodeURIComponent(addAttributesUrl1);
    
    var theUrl1 = addFeaturesUrl + obj1;            
    
    var xmlHttp = null;

    xmlHttp = new XMLHttpRequest();
    xmlHttp.open( "POST", theUrl1, false );
    xmlHttp.send( null );
}
0 Kudos
saurabhgupta2
New Contributor II

Hi jake

I am trying to modify one attribute in my feature service layer  in arcgis 10.2.2  using a json object .

Can u help me briefing out how to make that request . Can i do it without using any of the arcgis api .

regards

saurabh

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Hi Saurabh,

Yes, you can do this without the ArcGIS API for JavaScript.  Below is an example:

//json

var jsonObject = '{ "employees" : [' +

'{ "firstName":"John" , "lastName":"Doe" }]}';

//parse json

var obj = JSON.parse(jsonObject);

var lastName = obj.employees[0].lastName;

//update URL for feature service

var updateFeaturesUrl = 'http://server/arcgis/rest/services/Employees/FeatureServer/0/updateFeatures?features=

var updateAttributesUrl1 = '[{"attributes":{"OBJECTID":1,"NAME":"' + lastName + '"}}]' 

 

var obj1 = encodeURIComponent(updateAttributesUrl1); 

 

var theUrl1 = updateFeaturesUrl + obj1;             

 

var xmlHttp = null; 

xmlHttp = new XMLHttpRequest(); 

xmlHttp.open( "POST", theUrl1, false ); 

xmlHttp.send( null );