Dashboard data expression only returning one value

254
2
Jump to solution
03-08-2024 10:55 AM
Labels (1)
ScottFortman1
New Contributor III

Hi there,

I've been working on a data expression that creates a data dictionary using some existing fire hydrant fields to calculate a value for a new field.  I have the expression mostly working but it is only returning one feature.   I don't have any filters in my featureset and when I return the variable for Hydrants with the rest of the expression commented out, it returns all the features. I've done similar dictionaries in past without calculating a new value and have worked fine,  I just cant figure out what I'm missing here.  The resulting table should have a new field for PSI difference, calculated by the difference in Calculated PSI and Measured PSI.  

ArcGIS Enterprise 10.9.1

var tvwdportal = Portal('https://mapping.tvwd.org/portal')
var Hydrants = FeatureSetByPortalItem(tvwdportal,"b24772e427084f21b1f208a685d07fcc",5,['MaintainedBy','LifeCycleStatus','CalcStaticPSI','MeasuredStaticPSI', 'UniqueID'],True) ;


    
var out_dict = {
    'fields':[{name: 'PSIDifference', type: 'esriFieldTypeInteger'},
              {name: 'CalculatedPSI', type: 'esriFieldTypeInteger'},
              {name: 'MeasuredPSI', type: 'esriFieldTypeInteger'}],
    'geometryType': '',
    'features': []}



for (var f in Hydrants) {
    var f_CalcStaticPSI = Number(f['CalcStaticPSI'])
    var f_MeasuredPSI = Number(f['MeasuredStaticPSI'])
    var f_PSIDifference = Number(sum(f['CalcStaticPSI']- f['MeasuredStaticPSI']))
    
}
Push(out_dict['features'], {'attributes': {'CalculatedPSI':f_CalcStaticPSI,'MeasuredPSI': f_MeasuredPSI,'PSIDifference':f_PSIDifference}})

console(out_dict)
return FeatureSet(Text(out_dict))

 

 

 

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

Line 21 should be inside the for loop.

for (var f in Hydrants) {
    var f_CalcStaticPSI = Number(f['CalcStaticPSI'])
    var f_MeasuredPSI = Number(f['MeasuredStaticPSI'])
    var f_PSIDifference = Number(sum(f['CalcStaticPSI']- f['MeasuredStaticPSI']))
    Push(out_dict['features'], {'attributes': {'CalculatedPSI':f_CalcStaticPSI,'MeasuredPSI': f_MeasuredPSI,'PSIDifference':f_PSIDifference}})
}

View solution in original post

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor

Line 21 should be inside the for loop.

for (var f in Hydrants) {
    var f_CalcStaticPSI = Number(f['CalcStaticPSI'])
    var f_MeasuredPSI = Number(f['MeasuredStaticPSI'])
    var f_PSIDifference = Number(sum(f['CalcStaticPSI']- f['MeasuredStaticPSI']))
    Push(out_dict['features'], {'attributes': {'CalculatedPSI':f_CalcStaticPSI,'MeasuredPSI': f_MeasuredPSI,'PSIDifference':f_PSIDifference}})
}
0 Kudos
ScottFortman1
New Contributor III

Yep that was it.  I knew it was going something easy like that.  I really appreciate you getting a second pair of eyes on it and getting back to me.  Have a great weekend!

0 Kudos