Select to view content in your preferred language

Arcade: "Function not recognized" when parenthesis in field name

390
1
2 weeks ago
JonDiebold
New Contributor

I'm trying to use an Arcade script to generate dynamic text:

var selectedFeatures1 = $dataSources["dataSource_1-19934af200d-layer-22-19934afbfb4-layer-23-selection"].selectedFeatures;

var cnt = Count(selectedFeatures1);

if (Equals(cnt, 0)) {
  return 0;
}

return Average(selectedFeatures1, "st_area(shape)");

However, this causes the error "Function not recognized" to print to the console. If I use a numeric field with no parentheses, the average is calculated correctly. I've tried to escape the parentheses with backslashes, but the error persisted. Is there some other way to properly escape the field name?

I know I can just use the Dynamic Content -> Statistics functionality, but that shows the function name when no features are selected, and I'm also looking to write some custom calculations.

0 Kudos
1 Reply
NicoleJohnson
Frequent Contributor

Are you 100% sure the field name (not the alias) has parentheses in it? I just tried to add a field with parentheses and I can't do it.

Re: the function name showing when you do Dynamic Content -> Statistics, I prefer to just use Dynamic Content -> Expression with the same expression you'd calculate in Statistics, since you can give it a title that will show when no features are selected (this is nonsensical, but you get the idea--top is Dynamic Content -> Statistics, bottom is Dynamic Content -> Expression):

NicoleJohnson_1-1757945503534.png

To give it a title, just replace the default "Expression 1" title with your text:

NicoleJohnson_1-1757947358408.png

 

 

0 Kudos