How to call addFeatures  operation of a feature service programmatically

798
3
01-23-2012 06:27 AM
gangzhong
New Contributor
Hi, All,

I have a quick question of how to call add Features function from my code. Anybody could share your code snippet would be greatly appreciated. I got error message saying parameters are not valid if I try this:

request.features = {[
      {
      "attributes" : {
        "req_id" : "508389",
        "req_type" : "Graffiti Complaint - Public Property",
        "req_date" : "09\/19\/2009",
        "req_time" : "18:44",
        "address" : "11TH ST and HARRISON ST",
        "x_coord" : "6008925.0",
        "y_coord" : "2108713.8",
        "district" : "6",
        "status" : 1
      },
      "geometry" : {
        "x" : -122.41247978999991,
        "y" : 37.770630098000083
      }
    }
    ]};

url = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/0...";
  getJson(request, url, handler, errorHandler);
};

getJson: function (request, uri, handler, errorHandler) {

request.f = "json";

    dojo.io.script.get({
      url: uri,
   content: request,
      callbackParamName: "callback",
      load: function (result, args) {
        cmp.util.handler(result, args, uri, handler, errorHandler);
      },
      error: function (result, args) {
        cmp.util.errorHandler(result, args, uri, errorHandler);
      }
    });
  }

Should I use post method instead of get method even though my data is very small?

Thanks,

Gang
0 Kudos
3 Replies
KellyHutchins
Esri Frequent Contributor
Is there a reason why you aren't using the feature layer applyEdits method to add new features? There's a sample in the help here that shows how this works:

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/ed_feature_cre...
0 Kudos
derekswingley1
Frequent Contributor
I'm with Kelly- use the API instead of re-coding it.
0 Kudos
gangzhong
New Contributor
You guys are right. I didn't realize this applyEdit function.

Thanks!
0 Kudos