Select to view content in your preferred language

Arcade Pop-up Expression not Displaying All Fields and Attributes

747
3
02-19-2024 10:34 AM
Labels (3)
JasonSladinski1
Occasional Contributor

I have an Arcade Expression to not display any fields that have attributes that are null in the pop-up in the New Map Viewer.  When I test it, it shows the dictionary correctly.  I then configure the pop-up to use the expression in a Text element (I've also tried it as an Arcade element), and it will only display 3 attributes (GlobalID, OBJECTID, and WBS_Number).  If I turn the pop-ups off and then back on again, it'll show all of the attributes without any nulls like it's supposed to, but if I click on a feature, it displays only 3 fields.  I've tried everything I can think of, so any help or insight is appreciated.

Arcade Expression with test:

// Get all the field names
var fieldNames = Schema($feature).fields;

// Initialize an empty dictionary to store non-null attributes
var nonNullAttributes = {};

// Iterate over each field
for (var i in fieldNames) {
    var fieldName = fieldNames[i].name;
    var fieldValue = $feature[fieldName];

    // If the field value is not null, add it to the nonNullAttributes dictionary
    if (!IsEmpty(fieldValue)) {
        nonNullAttributes[fieldName] = fieldValue;
    }
}

// Return the non-null attributes
return nonNullAttributes;

 

JasonSladinski1_1-1708367265071.png

Pop-up Configuration:

JasonSladinski1_0-1708367456255.png

Simple Text Element configuration with just the expression:

JasonSladinski1_1-1708367495490.png

 

 

Correct Pop-up when first opened or after turning pop-ups off and on:

JasonSladinski1_0-1708367242022.png

Incorrect pop-up after clicking on features:

JasonSladinski1_2-1708367610297.png

 

0 Kudos
3 Replies
JohnEvans6
Regular Contributor

You'd need to post all your code if you can, but at a glance your output shouldn't be a dictionary I don't think. What is your return statement?

0 Kudos
JasonSladinski1
Occasional Contributor

Sorry, I thought I had the full code in the image, but Here is the code:

// Get all the field names
var fieldNames = Schema($feature).fields;

// Initialize an empty dictionary to store non-null attributes
var nonNullAttributes = {};

// Iterate over each field
for (var i in fieldNames) {
    var fieldName = fieldNames[i].name;
    var fieldValue = $feature[fieldName];

    // If the field value is not null, add it to the nonNullAttributes dictionary
    if (!IsEmpty(fieldValue)) {
        nonNullAttributes[fieldName] = fieldValue;
    }
}

// Return the non-null attributes
return nonNullAttributes;
0 Kudos
Alex_at_Exprodat
Occasional Contributor

I have found that removing the Fields list pop-up element is an issue in the new Map Viewer. Or having only a few fields selected. When you click on a feature, the map checks specifically for the Fields list element to get the list of fields it should send to the feature service for querying. So even if you have them defined in other pop-up elements, they simply won't exist in the query data that is returned from the service.

Luckily, there is a very simple solution. Have a look at the Arcade Expects Function. You can specify the list of fields you want to use for calculating your pop-up element expression. Or, to just return all fields available for processing, add this code to the top of your pop-up expression:

Expects($feature, '*')
0 Kudos