I'm writing a data expression to show which polygon (mmz) each point (leaks) resides within. I also need to keep a few fields from the leaks feature. I can populate the 'mmz' field, but I'm having trouble getting the other fields I need. Here's what I have so far and the results:
var port = Portal('my portal')
var mmz = FeatureSetByPortalItem(port, 'c879aa9267604224a3f6d492fc997a50', 7,['ZONE_NAME'],true)
var leaks = FeatureSetByPortalItem(port, '44fa0f9330e449c289dfadf2553d805b', 0,['leakloss','leaktype','dateshot','leaks_count','material','maindiameter'],true)
var features = []
var feat
for (var zone in mmz){
var pts = Contains(zone,leaks)
for (var pt in pts){
feat = {attributes:{
mmz: zone ['ZONE_NAME'],
leakloss: pt ['leakloss'],
leaktype: pt ['leaktype'],
dateshot: pt ['dateshot'],
leaks_count: pt ['leaks_count'],
material: pt ['material'],
maindiameter: pt ['maindiameter']
}
}
Push(features,feat)
}
}
var dict = {
fields: [
{name: "mmz", alias:"Zone", type:"esriFieldTypeString"},
{name: "leakloss", alias:"Gallons Lost", type:"esriFieldTypeInteger"},
{name: "leaks_count", alias:"Number of Leaks", type:"esriFieldTypeInteger"},
{name: "leaktype", alias:"Leak Type", type:"esriFieldTypeString"},
{name: "dateshot", alias:"Date", type:"esriFieldTypeDate"},
{name: "material", alias:"Material", type:"esriFieldTypeString"},
{name: "maindiameter", alias:"Diameter", type:"esriFieldTypeInteger"},
],
geometryType:"",
features:features
}
return FeatureSet(Text(dict))
Results:
Solved! Go to Solution.
I don't really see anything obviously wrong with the expression... You've confirmed the fields in the points layer has values, and that they're compatible with an integer field?
Data Expressions also tend to have trouble with Date fields. Try replacing this line:
dateshot: pt ['dateshot'],
with this:
dateshot: Number(pt['dateshot']),
Also, there are spaces between zone / pt and the bracketed attribute name, and there shouldn't be.
I don't really see anything obviously wrong with the expression... You've confirmed the fields in the points layer has values, and that they're compatible with an integer field?
Data Expressions also tend to have trouble with Date fields. Try replacing this line:
dateshot: pt ['dateshot'],
with this:
dateshot: Number(pt['dateshot']),
Also, there are spaces between zone / pt and the bracketed attribute name, and there shouldn't be.
Adding the Number function to the date field worked, but I also had to add the Text function to string field types for those values to show up.
Thanks for your help.
I also had to add the Text function to string field types for those values to show up
That's weird, this conversion should happen automagically.
The problem with Date fields is something that leads to confusion quite regularly. Please consider lending your support to this idea to hopefully get that fixed:
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