"Test execution error" in Arcade expression

2935
1
Jump to solution
07-02-2023 03:55 PM
swhitcombMCC
Occasional Contributor

I'm getting an error when writing an Arcade expression for a pop-up.

I have a table called "Rose Classes" with two fields: "Class" and "Description". I have a feature layer with a field called "Class". The Class field in the table matches the Class field in the feature layer. For a given Class within the feature layer, I want to return the Description for that Class from the Rose Classes table.

I asked ChatGPT for help and got the code below, which outputs "Test execution error: Execution error - Cannot access value using a key of this type. Verify test data."

I am very new to Arcade, so I don't even know where to begin to debug this code. I wrote in some return commands and was able to return everything but the final step.

var classesTable = FeatureSetByName($map, 'Rose Classes');
var currentClass = $feature.Class;

var matchingFeatures = Filter(classesTable, 'Class = @currentClass');
var description = '';

if (Count(matchingFeatures) > 0) {
  description = matchingFeatures[0].Description;
}

return description;
0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

matchingFeatures is a Featureset, a collection of Features. While it would be cool to access the Features by their index, that's not how it works. You can get the First() feature, though.

var classesTable = FeatureSetByName($map, 'Rose Classes')
var currentClass = $feature.Class

var matchingFeature = First(Filter(classesTable, 'Class = @currentClass'))
return IIf(matchingFeature == null, '', matchingFeature.Description)

Have a great day!
Johannes

View solution in original post

1 Reply
JohannesLindner
MVP Frequent Contributor

matchingFeatures is a Featureset, a collection of Features. While it would be cool to access the Features by their index, that's not how it works. You can get the First() feature, though.

var classesTable = FeatureSetByName($map, 'Rose Classes')
var currentClass = $feature.Class

var matchingFeature = First(Filter(classesTable, 'Class = @currentClass'))
return IIf(matchingFeature == null, '', matchingFeature.Description)

Have a great day!
Johannes