Select to view content in your preferred language

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

138
14
Sunday
WFCAdmin
Occasional Contributor

I am making an online experience and need help with Pop-ups

I have a point layer that contains my company's environmental DNA sample results. There are over 1000 data points, containing information on over 20 species. The point attributes include 46 fields.

When a point is selected in the map, I would like the viewer to only see those fields in the pop-up window that have data for that particular point, instead of having to scroll through 46 fields to find the pertinent DNA results.

 

For example,

For this point, I would like the following pop-up window to omit all the empty rows (red slashes).

WFCAdmin_0-1739752969726.png

Can someone help me with this appropriate arcade expression?

I prefer the default pop-up look. No fancy headings or color are needed.

If you could provide an example that would be great!

Here are a couple of the fields in my data set.

Chinook_Salmon_DNA_Detected_ 
 
NumPos_ChinookWells 
 
Coho_Salmon_DNA_Detected_ 
 

NumPos_CohoWells

Bull_Trout_DNA_Detected_
 

NumPos_BullTWells

Thank you!!

0 Kudos
14 Replies
gis_KIWI4
Frequent Contributor

@WFCAdmin - 

Try this - 

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


var excludeFields = ["OBJECTID", "EditDate"];


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

    if (!IsEmpty(value) && value != "" && IndexOf(excludeFields, key) == -1) {
        Push(fieldInfos, { fieldName: key });
        attributeValues[key] = value;
    }
}


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

 

 

This also allows a provision to remove certain fields like "ObjectID" and other tracking fields.
An example below - 

gis_KIWI4_0-1739851381642.png

 

WFCAdmin
Occasional Contributor

Thank you so much!!!

Sorry, I am a total novice with Arcade.

For the fields line, I bracket each field with ' ' and separate each field with a comma? Do I close out the fields row with anything special?

Here is an example

return {
    type: 'BULL_DNA_Detected', 'Num_BULL_Wells', 'DOVN_DNA_Detected', 'Num_DOVN_Wells'
    fieldInfos: fieldInfos,
    attributes: attributeValues
};
0 Kudos
gis_KIWI4
Frequent Contributor

The arcade code is fully dynamic. No need to mention what fields to output. The only time you might want to specify the fields is in 

var excludeFields = ["OBJECTID", "EditDate"];

 

These fields will be removed regardless if they are null or not.

 

 

WFCAdmin
Occasional Contributor

Awesome!

I am getting very close! Thank you gis_KIWI4!!

I am struggling with where to imbed the expression.

I notice that it will replicate the fields list filtered perfectly, omiting all the empty fields, but only if I add the expression after the fields list.

If I remove the fields list and only only include the expression then nothing will pop up.

0 Kudos
RhettZufelt
MVP Notable Contributor

To get this to work, I had to remove the field list, then add a new Arcade content and embed the code there.

RhettZufelt_0-1739984945581.png

Then it will draw the popup table correctly.

RhettZufelt_1-1739984979263.png

 

R_

 

 

0 Kudos
WFCAdmin
Occasional Contributor

Also, if it were possible to have the resulting popups use the display name instead of the field name, that would be amazing!

 

0 Kudos
gis_KIWI4
Frequent Contributor

Here is the code to use display names - 

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
};

 

Here you can see the Highlighted fields have had the Display Name (ignore the other fields). 
The test layers has Display name and Field Name the same. 

gis_KIWI4_0-1740005814774.png

 

 

WFCAdmin
Occasional Contributor

Thank you gis_KIWI4!

So here is the issue that I am having.

If I simply have my title and the arcade expression I get only the title in the pop-up.

If I have the title, the field list with all 46 fields checked on, and the arcade expression, I get the full list followed by the abbreviated list. The abbreviated list works perfectly this way always filtering out the empty fields, but it defeats the purpose because the pop-up is still clogged with a bunch of blank data to scroll through.

Any suggestions?

 

If on the other hand I add a fields list below the arcade expression I get

 

0 Kudos
gis_KIWI4
Frequent Contributor

I am not sure why that is happening.

I only have the title and arcade expression and it works. 

Do you have any attribute expressions that might be causing this iss

0 Kudos