Select to view content in your preferred language

esriFieldTypeDate in Data Expression in Dashboard doesn't work

1587
4
Jump to solution
11-23-2022 04:05 PM
Scott_Sambell
Frequent Contributor

Im creating a feature set using a data expression in a dashboard.  Its all pretty straightforward stuff.

I've created a dictionary with just four fields.  Two strings, a double and a date field

//there is a heap of stuff before this, but you get the idea.  I've created some variables and populated a dictionary with them
var new_features_dictionary = {
    'geometryType': '',
    'fields': [
        {'name': 'tasky', 'type': 'esriFieldTypeString'},
        {'name': 'group', 'type': 'esriFieldTypeString'},
        {'name': 'hours', 'type': 'esriFieldTypeDouble'},
        {'name': 'datedone', 'type': 'esriFieldTypeDate'}
    ],
    'features': new_feature_list
}

return FeatureSet(text(new_features_dictionary))

 

The string fields and double field work exactly as expected but no matter what i do i cannot get the date field to populate.  All i am doing is taking the date field from an existing feature layer and passing it through to the new feature set.  There are no calculations, nothing technical at all.

It seem that esriFieldTypeDate just does not work in data expressions.  Please someone tell me this isnt the case.

(p.s yes, i even tried a million different way of converting the date to text and back to date again. When i make the date field a esriFieldTypeString, the feature set populates beautifully.  However a text date in a dashboard is completely useless.  Im totally out of ideas)

Scott
0 Kudos
1 Solution

Accepted Solutions
Scott_Sambell
Frequent Contributor

Nevermind.  I figured it out. 

You have to put number() before the variable if you want to populate a date field.

var new_record = {
                'attributes':{
                    'hours': f['totalhours'],
                    'group': f['groupnameland'],
                  'datedone': number(f['datetask']),
//etc....

 

Who knew right? 🙄

Scott

View solution in original post

4 Replies
Scott_Sambell
Frequent Contributor

Nevermind.  I figured it out. 

You have to put number() before the variable if you want to populate a date field.

var new_record = {
                'attributes':{
                    'hours': f['totalhours'],
                    'group': f['groupnameland'],
                  'datedone': number(f['datetask']),
//etc....

 

Who knew right? 🙄

Scott
by Anonymous User
Not applicable

How are you going Scott? How did you figure this out? This may be the stumbling block that is tripping up my expression. Going to see if this works before I post my issue here. I probably will post anyway but this may get me further along!

0 Kudos
JohannesLindner
MVP Frequent Contributor

Glad that you got it to work.

 

Who knew right? 

Almost nobody. This is a problem that regularily trips up users both new and experienced. It's a completely illogical design decision that noone expects (and neither should they).

I'm just gonna plug my Idea about this here, I'm glad for everyone that lends their support to it:

Arcade: Allow Date() values in date fields (esriFi... - Esri Community


Have a great day!
Johannes
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