Select to view content in your preferred language

Data Expression Returning Empty

483
2
08-22-2023 02:34 PM
Labels (1)
EBurridge
New Contributor

I have tried this 8 ways to Sunday and I can't get it to work.  This is the furthest I have gotten, and I am hoping someone can help me get the rest of the way.  We are operating version 10.9.1 on our portal server.

I am trying to create a data expression for a dashboard that is fed by Survey 123.  I am accessing the "Results" layer, and I own it.  Editing is enabled, but Sync is disabled.  All I really want to do is add 5 fields to the original and calculate them based on the incident date, I need to have the ability to aggregate on Year, Month, Day of Week, Hour and Quarter.  The calculations appear to be working, but the output comes out with a list of empty fields.

here is my code:

var portal =Portal('https://egis-sige.rcmp-grc.gc.ca/portal');
var fs = FeatureSetByPortalItem(portal, '6324abd8c2744757871fe4ee85272666',1,['incident_date', 'duration', 'district', 'detachment','tasks', 'foi', 'incident_summary','incident_no'],false);

var s = Schema(fs)
var sFldCount = Count(s.fields)
var newFldCount = sFldCount

s.fields[newFldCount] = {alias: 'Year', defaultValue: null, editable: true, length: 5, name: 'occ_year', type: 'esriFieldTypeString'}
s.fields[newFldCount+1] = {alias: 'Month', defaultValue: null, editable: true, length: 25, name: 'occ_month', type: 'esriFieldTypeString'}
s.fields[newFldCount+2] = {alias: 'Day of Week', defaultValue: null, editable: true, length: 25, name: 'dow', type: 'esriFieldTypeString'}
s.fields[newFldCount+3] = {alias: 'Hour', defaultValue: null, editable: true, length: 5, name: 'occ_hour', type: 'esriFieldTypeString'}
s.fields[newFldCount+4] = {alias: 'Quarter', defaultValue: null, editable: true, length: 5, name: 'quarter', type: 'esriFieldTypeString'}

var returnFS = {
fields: s.fields,
geometryType: '',
features:[],
}
console(returnFS)
var index = 0;

for (var f in fs) {
returnFS.features[index] = {
'fields': {
'incident_date': f.incident_date,
'duration': f.duration,
'district': f.district,
'detachment': f.detachment,
'tasks': f.tasks,
'foi': f.foi,
'incident_summary': f.incident_summary,
'incident_no': f.incident_no,
'occ_year': Text(f.incident_date,"yyyy"),
'occ_month': Text(f.incident_date, "MMMM"),
'dow': Text(f.incident_date, "dddd"),
'occ_hour': Text(f.incident_date, "HH"),
'quarter': IIF(ISOMonth(f.incident_date)>9, "Q3", IIF(ISOMonth(f.incident_date)>6,"Q2",IIF(ISOMonth(f.incident_date)>3,"Q1","Q4")))
}

}
index++; };
console(returnFS)
return FeatureSet(Text(returnFS))

I have tried the above, I have tried populating a "features" array and feeding that to the dictionary, and I have tried the Push() function in a For Loop to push a feature into the Features element of the dictionary.  this is the only version that pretends to work, the features are going in/coming out, but not with all their attributes:

EBurridge_0-1692739891958.png

Thank you!!

0 Kudos
2 Replies
JohannesLindner
MVP Frequent Contributor

Replace line 25 with this:

'incident_date': Number(f.incident_date),

 

In previous Arcade versions, Date values had to be submitted as Numbers. This problem is fixed in AGOL and will probably be fixed in Enterprise 11.2

 


Have a great day!
Johannes
0 Kudos
EBurridge
New Contributor

Thank you @JohannesLinder! I changed just that row, and nothing changed about my output - it is all the same, about 2000 features with not a single populated attribute.

I then changed the field definitions in the dictionary to make the incident_date a numeric field, but that also didn't work.

Any other suggestions?

0 Kudos