I'm attempting to create an Attribute Rule Calculation that counts the number of occurrences of a given value ("x") in a number of fields in a dataset. I want to update a different field ("IssuesCount") in the said dataset with that number. In total, there are 15 fields that I need to check.
My thought was that I would start with a list of fields names that I want to check then dynamically generate the field names, check to see if they contained "x", then count up the occurrences. But I'm struggling to dynamically generate the field names from the list.
Here's the list of fields :
var fieldList = ['IssueAdjacentProperty', 'IssueCultivation',
'IssueFoodPlots', 'IssueHaying', 'IssueTimberHarvestCutting',
'IssueBurning', 'IssueNewExpandedTrail', 'IssueNewExpandedRoad',
'IssueParkedEquipment', 'IssueNewBuildings', 'IssueGrazingLivestock',
'IssueCommercialSeed', 'IssueUtilities', 'IssueMining', 'IssueImpervious',
'IssueHydrology', 'IssueUnauthorizedEasement', 'IssueWaste', 'IssueMowing',
'IssueOther', 'IssueExpandedYard', 'IssueFencing', 'IssueErosion',
'IssueStormwater', 'IssueYardWaste']
And here's me trying to dynamically generate the field names to check the values:
// Dynamically generate field name
for (var f in fieldList){
// Doesn't work as it returns the literal string of '$feature.0'
var fieldName = "$feature." + f
// Return the value in the field.
// This part doesn't work because 'fieldName' equals
// '$feature.0' at this point and Arcade is looking
// for a field called 'fieldName' here.
var checkValue = $feature.fieldName
// Then do something like loop through fields checking for 'x'
// (unless there is a more efficient way to do that too)
var counter = 0
if (checkValue == 'x') {
counter++;
}
}
// Return the count
return counter;
I think once I get this field name piece figured out I have, I know what to do on the rest of the Attribute Rule side of things.
Thanks for any help!
Todd Lusk, Senior GIS Specialist
Dakota County, MN