Arcade dictionary to FeatureSet

219
4
Jump to solution
4 weeks ago
MarcHoogerwerf_TAP
New Contributor

Hi,

I'm trying to convert a dictionary to a FeatureSet in an Arcade data Expression. Everything works well until I use a Date field.

The following works ok, just inserting null values for the date field

var data_dict = {
'fields': [
{'name': 'EditDate','type': 'esriFieldTypeDate'},
{'name': 'country','type': 'esriFieldTypeString'},
{'name': 'status','type': 'esriFieldTypeInteger'}
],
'geometryType':'',
'features': []
};

for (var i=0; i < 10;i++) {
data_dict.features[i] = {
'attributes': {
'EditDate': null,
'country': 'NL',
'status': 230
}
}
}
Console(data_dict)
var fs = FeatureSet(Text(data_dict))
return fs

 It results in a FeatureSet with empty values for the date field and all other field filled.

However, if I try Now() or Text(Now(),"YYYY-MM-DD") or Timestamp() or just a date like string '2021-04-14' :

var data_dict = {
'fields': [
{'name': 'EditDate','type': 'esriFieldTypeDate'},
{'name': 'country','type': 'esriFieldTypeString'},
{'name': 'status','type': 'esriFieldTypeInteger'}
],
'geometryType':'',
'features': []
};

for (var i=0; i < 10;i++) {
data_dict.features[i] = {
'attributes': {
'EditDate': Now(),
'country': 'NL',
'status': 230
}
}
}
Console(data_dict)
var fs = FeatureSet(Text(data_dict))
return fs

 I end up with an empty Featureset

Any ideas?

Regards,

Marc

0 Kudos
1 Solution

Accepted Solutions
Peter_Klingman
Esri Regular Contributor

Hi @MarcHoogerwerf_TAP - the date field is looking for a UNIX timestamp, which you can create in Arcade with DateDiff().

var start = ToLocal(Date(1970, 0, 01, 0, 0, 0, 0))
var dt = DateDiff(Now(), start, 'milliseconds')

 

Hope this helps!

-Peter 

View solution in original post

4 Replies
Peter_Klingman
Esri Regular Contributor

Hi @MarcHoogerwerf_TAP - the date field is looking for a UNIX timestamp, which you can create in Arcade with DateDiff().

var start = ToLocal(Date(1970, 0, 01, 0, 0, 0, 0))
var dt = DateDiff(Now(), start, 'milliseconds')

 

Hope this helps!

-Peter 

View solution in original post

MarcHoogerwerf_TAP
New Contributor

Hi Peter,

Brilliant! It works now. Thanks

- Marc

DavidPike
MVP Regular Contributor

@Peter_Klingman was scratching my head for a while on this, after a quick google it led me here - thanks for your solution.

Peter_Klingman
Esri Regular Contributor

Glad it was a quick find and helped out!