Good morning folks, hope all is well, so i have a field say attribute1 that has "Yes", "No" and "NA" list values to choose from in the Field Maps survey.
Then i have another field say attribute2 that will be auto-populated such that whenever the user select Yes, Arcade will count it and return "Value 1" the first time. Similarly, the next time the user select "Yes", Arcade will return "Value 2" and so on kind of like a counter.
Desired output:
Attribute1 Attribute2
Yes Value 1
Yes Value 2
No <Null>
No <Null>
NA <Null>
Yes Value 3
Arcade expression:
// Store the layer as a variable
var layer = FeatureSetByName($map, "sf")
// Filter the attribute value
var YesVal = Filter(layer, "attribute1" == "Yes")
// Count the number of "Yes" features
var YesCount = Count(YesVal)
// If the current feature's attribute is "Yes", add 1 to the count
if ($feature.attribute1 == "Yes") {
return "Value", yesCount + 1;
} else {
return null;
}
Error:
Test execution error: t.charAt is not a function. Verify test data.
You are using YesCount at the beginning but in the loop you have yesCount. That could be it.
But as posted this will all break if someone deletes a record in the middle.
Hi @KenBuja , thank you for pointing that out so yes the domain values and labels are the same as you can see below
However, as if this moment they are no Yes values in the attribute it self, right now they are all Not rated
So your line 5 now looks like this?
var YesVal = Filter(layer, "attribute1 = 'Yes'")
And as @KenBuja said, if your code and label are different, you could be getting an empty featureset from that filter. Maybe wrap that count expression with an if statement checking if your featureset is empty.
if (!isEmpty(first(YesVal))) {
var YesCount = Count(YesVal)
} else YesVal = 0
Hi @Ed_ ,
Try the solution below. My assumption is you it may be something to do with the layer name but it is hard to say what the issue is.
// Store the layer as a variable
var layer = FeatureSetByName($map, "sf")
// Filter the attribute value and count values
var FilterField = "attribute1"
var FilterValue = 'YES'
var YesCount = Count( Filter( layer , FilterField + ' = @FilterValue' ) )
// If the current feature's attribute is "Yes", add 1 to the count
iif ($feature.attribute1 == "Yes" , yesCount + 1 , null )
Also, is your problem similar to the one found on stack overflow. Because if it is, then that would help anyone else here point you in the right direction.