Feature not being created due to date field type

801
6
Jump to solution
08-11-2022 09:23 PM
Aeseir
by
Occasional Contributor

Very simply I am trying to enrich a feature on creation by adding a createdAt datetime. However when I add this additional attribute, the feature does not get created.

I am learning how to add this attribute so that in future I can filter features by date and/or create heatmaps.

 

Code is very simple:

//feature layer setup
 const featureLayer = new FeatureLayer({
      geometryType: "polygon",
      title: "Test Feature Layer",
      source: [],
      objectIdField: "UniqueId",
      spatialReference: {
        wkid: 102100
      },
      fields: [{
        name: "id",
        alias: "UniqueId",
        type: "guid"
      }, {
        name: "description",
        alias: "Description",
        type: "string"
      }, {
        name: "createdDate",
        alias: "CreatedDate",
        type: "date"
      }],
      outFields: ["*"],
      popupTemplate: popupTemplateDetails,
    });

// adding feature
var polygon = this.addPolygonGraphic({ id: e.id, description: e.description, createdDate: new Date(2019, 4, 25) }, rings);

this.areaFeatureLayer.applyEdits({ addFeatures: polygonFeatures });


function addPolygonGraphic(attributes: { [key: string]: any }, rings: any) {
    var polygon = new Polygon({
      rings: rings,
      spatialReference: {
        wkid: 102100
      }
    });

    var graphic = new Graphic({
      geometry: polygon,
      attributes: attributes
    });
    return graphic;
  }

 

What am I missing here?

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

I don't know about the Javascript API, but in Arcade (which seems to share a big part of the feature set declaration with the JS API), you have to supply an integer (epoch, number of milliseconds since 1970-01-01) to the date field.

This is how it would look in Arcade:

 

Number(Date(2019, 4, 25))

 


Have a great day!
Johannes

View solution in original post

0 Kudos
6 Replies
JohannesLindner
MVP Frequent Contributor

I don't know about the Javascript API, but in Arcade (which seems to share a big part of the feature set declaration with the JS API), you have to supply an integer (epoch, number of milliseconds since 1970-01-01) to the date field.

This is how it would look in Arcade:

 

Number(Date(2019, 4, 25))

 


Have a great day!
Johannes
0 Kudos
Aeseir
by
Occasional Contributor

That was it, i had to convert it to number, which is annoying

0 Kudos
Aeseir
by
Occasional Contributor

@JohannesLindner how do you manage the time offset due to timezones, epoch ignores timezones

0 Kudos
JohannesLindner
MVP Frequent Contributor

Again, no idea how to do it in the JS API.

Arcade has the functions ToUTC() and ToLocal(), which convert your local date to UTC or vice versa.

JohannesLindner_0-1660542054906.png

 


Have a great day!
Johannes
0 Kudos
Aeseir
by
Occasional Contributor

See that's how i started with initially, passing the date format, but for some reason it is not accepted by argcis. Only epoch number is accepted.

0 Kudos
DavidNyenhuis1
Esri Contributor

With this week's update to Arcade and ArcGIS Dashboards, date fields in feature set constructors now just work. You no longer have to wrap dates with Number() if you pass the dictionary into the FeatureSet() function (which as of this release accepts a dictionary as opposed to only text based JSON).

Instead of:

return FeatureSet(Text(dict))

Do this:

return FeatureSet(dict)

Learn more in this blog post

NOTE: For Enterprise users, this update is targeted for 11.2

0 Kudos