How do I include a parameter of type 'esriFieldTypeDate ' in a POST request to FeatureService REST method applyEdits()?

1265
2
11-28-2017 05:46 PM
mfcallahan
Occasional Contributor II

I'm attempting to insert some records into my feature service using the applyEdits() method, however I'm receiving an error message because I'm not sure how to include data for a field in the feature service table that is of type 'esriFieldTypeDate'.  Here is some quick sample code - I have an object that contains my feature to be inserted:

var newFeature = {
   "geometry": { 
      "x": -97.2736,
      "y": 32.8164
   },
   "attributes": {
      "SiteID": 999,
      "Name": "Test Site 1",
      "LeaseSigned": "12/1/2016, 9:00 AM"
   },
   "spatialReference": {
      "wkid": "102100"
   }
};

var features = [];
features.push(newFeature);

I also have an object that contains the input params for applyEdits():

var params= {
   f: 'json',
   adds: JSON.stringify(features),
   updates: "",
   deletes: "",
   gdbVersion: "",
   rollbackOnFailure: true,
   useGlobalIds: false,
   attachments: ""
};

However, I am receiving this error because I'm not sure how to format the input data for esriFieldTypeDate:

{
   "error":{
      "code": 400,
      "message":"Unable to complete operation.",
      "details":["Setting of value for LeaseSigned failed."]
   }
}

Does anybody know how to format the date time field correctly or can point me in the direction of some examples?  I've tried all different types of date formats but can't seem to figure this out.  Thanks!

0 Kudos
2 Replies
RandyBurton
MVP Alum

I believe your date/time needs to be in epoch time (Unix time) with milliseconds when using json formatting.

"LeaseSigned" : 1480615200000‍‍
0 Kudos
RandyBurton
MVP Alum

And if using a service like AGOL, you may also need to convert your date/time into UTC.

0 Kudos