Select to view content in your preferred language

Omit Fields without data from the Pop up Window on Online MapViewer

267
5
Jump to solution
02-22-2025 10:41 AM
WFCAdmin
Occasional Contributor

I recently reached out for help on this topic and @RhettZufelt and @gis_KIWI4 we very helpful in getting me going.

@gis_KIWI4provided me with the following arcade expression.

var attributes = Dictionary($feature)["attributes"];
var fieldInfos = [];
var attributeValues = {};


var excludeFields = ["OBJECTID", "EditDate"]; //Use this to exclude any fields, null or not null


var layer_schema = Schema($feature);
var fieldAliases = {};


for (var i = 0; i < Count(layer_schema.fields); i++) {
    var field = layer_schema.fields[i];
    fieldAliases[field.name] = field.alias;
}


for (var key in attributes) {
    var value = attributes[key];


    if (!IsEmpty(value) && value != "" && IndexOf(excludeFields, key) == -1) {
        var displayName = key; // Default to field name
        
        // Use alias if available
        if (HasKey(fieldAliases, key)) {
            displayName = fieldAliases[key];
        }
        
        Push(fieldInfos, { fieldName: key, label: displayName });
        attributeValues[key] = value;
    }
}



return {
    type: 'fields',
    fieldInfos: fieldInfos,
    attributes: attributeValues
};

 

This returns the pop-ups perfectly, with display names rather than field names.

My issue is, it only works on the first point I select. If I click on a second point, it won't pull up any pop-ups.

If I then click on another layer with a pop-up and then back on the filtered pop-up layer it works again. It's like it only works once and then needs something to reset it.

Any help troubleshooting this would be much appreciated!

0 Kudos
1 Solution

Accepted Solutions
RhettZufelt
MVP Notable Contributor

I tried this modification, but made no difference.  Would still work as expected, once, then would only show system managed fields. 

However, playing around with it, I noticed that it will display the system managed fields AND any fields that are loaded elsewhere like the title or field list.

So, figured I'm make sure and 'load' all fields into the script and I tested both the original and modified script by adding:

Expects($feature, '*')    

as the first line.

Now it seems to be working as expected, and populates all non-empty fields (that aren't in the exclude list) each time I click on a feature.


It still re-orders them alphabetically though, have not figured that one out yet.......

R_

View solution in original post

5 Replies
RhettZufelt
MVP Notable Contributor

Looking into this some more, I am seeing the same thing, but not sure why.

However, after the first one, it is returning data, but ONLY the system managed fields (Creator, GlobalID, OBJECTID, etc.) that I don't have in the excludeFields list.

So, for whatever reason, it only system-maintained fields after the initial popup until I select another layer then switch back.

I have also noticed that it only behaves this way when I have editing capabilities.  If I open share this and open it with just read, then I never get the full popup, just the non-excluded system fields...

Maybe this will help someone figure out why?

R_

 

0 Kudos
AustinAverill
Frequent Contributor

I've found that for whatever reason, the pop-up arcade profile seems to want to quit working when there are multiple assignments on a variable and nested if statements. Not sure if this is performance related or what.

 

I modified the second for loop in the following ways. First - I added a "!IsNan()" condition to the primary if statement, in the event there is a "NaN" value for extra coverage (you can omit this change if you want). Additionally, I have eliminated the nested if statement, as this is redundant and possibly impacting the functionality in my experience. All fields will return with a field alias, even if the field alias is just the field name. It is simpler to just set the display name to the value from the field alias dictionary. 

 

In testing around in my own layer, I have not been able to replicate the issue since making this modification.

for (var key in attributes) {
    var value = attributes[key];

    // Added !IsNan(value) condition
    if (!IsNan(vale) && !IsEmpty(value) && value != "" && IndexOf(excludeFields, key) == -1) {
        var displayName = fieldAliases[key]; // Default to field name
        
        // Removing this for simplicity - All keys will have "aliases." 
				//Even fields without a formally defined alias will present with the fieldname as their alias.
				
				// Use alias if available
        //if (HasKey(fieldAliases, key)) {
        //    displayName = fieldAliases[key];
        //}
        
        Push(fieldInfos, { fieldName: key, label: displayName });
        attributeValues[key] = value;
    }

 

0 Kudos
RhettZufelt
MVP Notable Contributor

I tried this modification, but made no difference.  Would still work as expected, once, then would only show system managed fields. 

However, playing around with it, I noticed that it will display the system managed fields AND any fields that are loaded elsewhere like the title or field list.

So, figured I'm make sure and 'load' all fields into the script and I tested both the original and modified script by adding:

Expects($feature, '*')    

as the first line.

Now it seems to be working as expected, and populates all non-empty fields (that aren't in the exclude list) each time I click on a feature.


It still re-orders them alphabetically though, have not figured that one out yet.......

R_

WFCAdmin
Occasional Contributor

Yes!!!!!!

 

Thank you so much! It works!! 🙏

0 Kudos
WFCAdmin
Occasional Contributor

Thank you so much! Your script along with

Expects($feature, '*')    

At the beginning works!!

0 Kudos