Select to view content in your preferred language

Arcade Expression: No values returned by FeatureSet from Dictionary

1202
5
Jump to solution
08-21-2022 08:06 PM
pat_algura
New Contributor III

Hello!

I'm quite new to using data expressions with dashboards. My data contains water sample results and i wanted to assign a value for each period/date ranges. The data was filtered by different date ranges and I assigned them a value and wrote them in a new table. 

It worked just fine. However, when I tried to return a FeatureSet from the Dictionary, it's not returning any values even if the dictionary has features. Not sure what I'm missing...

palgura_j_2-1661137326749.png

 

palgura_j_1-1661137291847.png

Here's the code I wrote for reference:

var periods = [p1, p2, p3, p4, p5];
var features = [];
var feat;

var cnt = 0;
for (var ped in periods) {
var period = periods[cnt];
for (var p in period) {
feat = {
attributes: {
'objectid': p['objectid'],
'assetid': p['assetid'],
'wzonename': p['wzonename'],
'reservoir_id': p['reservoir_id'],
'sp_type': p['sp_type'],
'sample_date': p['sample_date'],
'sample_year': p['sample_year'],
'test_description': p['test_description'],
'result': p['result'],
'izparea': p['izparea'],
'period': 'p'+(cnt+1)
}
}
Push(features,feat)
}
cnt++;
}
//return features;
var samples = {
'fields':
[{'name': 'objectid', 'type': 'esriFieldTypeInteger'},
{'name': 'assetid', 'type': 'esriFieldTypeString'},
{'name': 'wzonename', 'type': 'esriFieldTypeString'},
{'name': 'reservoir_id', 'type': 'esriFieldTypeString'},
{'name': 'sp_type', 'type': 'esriFieldTypeString'},
{'name': 'sample_date', 'type': 'esriFieldTypeDate'},
{'name': 'sample_year', 'type': 'esriFieldTypeString'},
{'name': 'test_description', 'type': 'esriFieldTypeString'},
{'name': 'result', 'type': 'esriFieldTypeDouble'},
{'name': 'izparea', 'type': 'esriFieldTypeString'},
{'name': 'period', 'type': 'esriFieldTypeString'}
],
'geometryType': 'esriGeometryPoint',
'features': features
};
//return samples;
return FeatureSet(Text(samples));

Tags (2)
0 Kudos
2 Solutions

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

To post formatted code:

JohannesLindner_0-1661148750380.png

JohannesLindner_1-1661148777518.png

 

You have a date field in your feature set. For whatever stupid design reason, you can't input Date() values into date fields, you have to convert them to Number() first. I took the opportunity to make your for loop shorter.

var periods = [p1, p2, p3, p4, p5];
var features = [];

for (var cnt in periods) {
    var period = periods[cnt];
    for (var p in period) {
        // get the original attributes
        var copy_attributes = Dictionary(Text(p))['attributes']
        // cast the date to number
        copy_attributes['sample_date'] = Number(copy_attributes['sample_date'])
        // calculate the period
        copy_attributes['period'] = 'p' + (cnt + 1)
        // push into array
        Push(features, {'attributes': copy_attributes})
    }
}
//return features;
var samples = {
    'fields': [
        {'name': 'objectid', 'type': 'esriFieldTypeInteger'},
        {'name': 'assetid', 'type': 'esriFieldTypeString'},
        {'name': 'wzonename', 'type': 'esriFieldTypeString'},
        {'name': 'reservoir_id', 'type': 'esriFieldTypeString'},
        {'name': 'sp_type', 'type': 'esriFieldTypeString'},
        {'name': 'sample_date', 'type': 'esriFieldTypeDate'},
        {'name': 'sample_year', 'type': 'esriFieldTypeString'},
        {'name': 'test_description', 'type': 'esriFieldTypeString'},
        {'name': 'result', 'type': 'esriFieldTypeDouble'},
        {'name': 'izparea', 'type': 'esriFieldTypeString'},
        {'name': 'period', 'type': 'esriFieldTypeString'}
    ],
    'geometryType': 'esriGeometryPoint',
    'features': features
};
//return samples;
return FeatureSet(Text(samples));

Have a great day!
Johannes

View solution in original post

pat_algura
New Contributor III

Hi Johannes,

That works like a charm - You're heaven sent!
Yeah, I've seen some other thread with the other users having issues writing Dates too, but didn't expect that was the same issue as mine.


Thanks heaps!! 🙂
Have a great day!

View solution in original post

0 Kudos
5 Replies
JohannesLindner
MVP Frequent Contributor

To post formatted code:

JohannesLindner_0-1661148750380.png

JohannesLindner_1-1661148777518.png

 

You have a date field in your feature set. For whatever stupid design reason, you can't input Date() values into date fields, you have to convert them to Number() first. I took the opportunity to make your for loop shorter.

var periods = [p1, p2, p3, p4, p5];
var features = [];

for (var cnt in periods) {
    var period = periods[cnt];
    for (var p in period) {
        // get the original attributes
        var copy_attributes = Dictionary(Text(p))['attributes']
        // cast the date to number
        copy_attributes['sample_date'] = Number(copy_attributes['sample_date'])
        // calculate the period
        copy_attributes['period'] = 'p' + (cnt + 1)
        // push into array
        Push(features, {'attributes': copy_attributes})
    }
}
//return features;
var samples = {
    'fields': [
        {'name': 'objectid', 'type': 'esriFieldTypeInteger'},
        {'name': 'assetid', 'type': 'esriFieldTypeString'},
        {'name': 'wzonename', 'type': 'esriFieldTypeString'},
        {'name': 'reservoir_id', 'type': 'esriFieldTypeString'},
        {'name': 'sp_type', 'type': 'esriFieldTypeString'},
        {'name': 'sample_date', 'type': 'esriFieldTypeDate'},
        {'name': 'sample_year', 'type': 'esriFieldTypeString'},
        {'name': 'test_description', 'type': 'esriFieldTypeString'},
        {'name': 'result', 'type': 'esriFieldTypeDouble'},
        {'name': 'izparea', 'type': 'esriFieldTypeString'},
        {'name': 'period', 'type': 'esriFieldTypeString'}
    ],
    'geometryType': 'esriGeometryPoint',
    'features': features
};
//return samples;
return FeatureSet(Text(samples));

Have a great day!
Johannes
pat_algura
New Contributor III

Hi Johannes,

That works like a charm - You're heaven sent!
Yeah, I've seen some other thread with the other users having issues writing Dates too, but didn't expect that was the same issue as mine.


Thanks heaps!! 🙂
Have a great day!

0 Kudos
JohannesLindner
MVP Frequent Contributor

Glad to help.

Please accept the answer as solution, so that this question gets shown as resolved.


Have a great day!
Johannes
0 Kudos
JohannesLindner
MVP Frequent Contributor

Just posted an Idea about this, feel free to add your support:

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