Select to view content in your preferred language

Arcade Expression works but doesn't display properly in Popup

270
1
04-09-2025 08:55 AM
Labels (1)
ShwarnaBhattacharjee
New Contributor

I'm using an Arcade expression in a popup to display observed bird species counts along with an image for point feature layer. The code runs without errors in the Arcade editor. The image is also loading correctly from the "Image_url" field in pop-up.  However, the species count part is not showing up at all. Instead, I only see the fallback message "No Species Data Available"

Here is the Arcade expression:

// Dictionary to map species codes to full names
var speciesMap = {
    "EABL": "Eastern Bluebird",
    "MOBL": "Mountain Bluebird",
    "WEBL": "Western Bluebird",
    "PABU": "Painted Bunting",
    "AMGO": "American Goldfinch",
    "LEGO": "Lesser Goldfinch",
    "BHNU": "Brown-headed Nuthatch",
    "PYNU": "Pygmy Nuthatch",
    "RBNU": "Red-breasted Nuthatch",
    "WBNU": "White-breasted Nuthatch",
    "EATO": "Eastern Towhee",
    "SPTO": "Spotted Towhee"
};

// // Function to place image to the side of the text
function buildbox(imageURL, txt) {
    return '<figure class="table"><table><tbody><tr><td width=100px;height=100px><img src="' + imageURL + '" alt="" height=100 width=100 /></td><td width=20px></td><td>' + txt + '</td></tr></tbody></table></figure>';
     
   };

// Initialize an empty list for observed species
var validSpecies = [];

// Iterate through species dictionary
for (var speciesCode in speciesMap) {
    // Safely get value or null if field doesn't exist
    var speciesCount = When(
        IsEmpty($feature[speciesCode]), null,
        $feature[speciesCode]
    );

    if (!IsEmpty(speciesCount)) {
        Push(validSpecies, speciesMap[speciesCode] + ": " + speciesCount);
    }
}


// Format observed species text
var speciesText = Concatenate(validSpecies, TextFormatting.NewLine);

// Get image URL safely
var imgUrl = "";
if (HasKey($feature, "Image_url")) {
    imgUrl = $feature.Image_url;
}

// Debugging output: Check if speciesText is empty
if (IsEmpty(speciesText)) {
    speciesText = "<p style='color:pink;'>No species data available.</p>";
}

var finalText = buildbox(imgUrl, "<b>Observed Species Count</b><br>" + speciesText)

return{
    type : 'text',
    text : finalText
}

 This is the output result which I believe it'correctoutput_run.png

This is the web map link which one I am trying to configure the pop-up.

Questions:
  1. Is there something wrong with how I'm checking for IsEmpty($feature[speciesCode]) using When()?
  2. Could the issue be that these fields are not being recognized in Arcade?
  3. Is there a better way to dynamically access multiple field values for summary display in a popup?
I appreciate any insight or ideas on what might be going wrong here!
0 Kudos
1 Reply
ShwarnaBhattacharjee
New Contributor

I have been able to solve this problem!

0 Kudos