Feature not being created due to date field type

121
5
Jump to solution
08-11-2022 09:23 PM
Aeseir
by
New Contributor III

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 Regular 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
5 Replies
JohannesLindner
MVP Regular 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
New Contributor III

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

0 Kudos
Aeseir
by
New Contributor III

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

0 Kudos
JohannesLindner
MVP Regular 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
New Contributor III

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