I am working in ArcGIS Pro pop-ups Expressions and I have parsed together an Arcade script to search an attribute field in ArcGIS Pro for some words, and then return the words color-coded into the pop-up text. In the attribute table I have it setup so users can select an attribute from a drop down menu.
Here is my code:
// Define the attribute field and feature layer
var fieldName = 'disposition';
var layerName = 'HC_footprints';
// Get the value of the attribute field
var disposition = $feature[fieldName];
// Define colors for each disposition
var color;
switch (disposition) {
case 'Bad':
color = '#FF0000'; // Red
break;
case 'Fair':
color = '#A52A2A'; // Brown
break;
case 'Good':
color = '#90EE90'; // Light green
break;
case 'Inaccessible':
case 'Unknown':
color = '#808080'; // Dark grey
break;
default:
color = '#000000'; // Black for other cases
}
// Return the disposition with the appropriate color
return "<CLR>" + color + "</CLR>" + disposition;
When I run it it fails and says:
Test execution error: Unexpected token '{'.. Verify test data.
What is wrong with my code? I believe a better way to do it is to use an if/Tehn statement like below. I get close, just need to color code the words Bad as red, Good as green, Fair as brown, and Unknown or Inaccessible as black:
var disposition = $feature.disposition;
if (disposition == 'Good') {
return 'Good'
}
else if (disposition == 'Bad') {
return 'Bad'
}
else if (disposition == 'Fair') {
return 'Fair'
}
else if (disposition == 'Unknown') {
return 'Unknown'
}
else if (disposition == 'Inaccessible') {
return 'Inaccessible'
}
else {
return 'no data'
}