don't show null values in popup

668
6
12-12-2023 07:00 AM
Labels (1)
temprobertcottreau131313
Occasional Contributor II

I have a layer with about 50 fields that show up as 50 rows in the popup.  Most of these are Null values.

Is there a way to create an expression that will set it up to not show the fields with Null values in the popup without typing 50 expressions?

I've seen HTML solutions and ideas for Map Viewer Classic but I'm using the New Map Viewer.

Thanks to all.

Tags (3)
0 Kudos
6 Replies
jcarlson
MVP Esteemed Contributor

Yes! You can do this very easily with an Arcade popup element and a single expression. You can build a fields list object programmatically and check for nulls and skip them.

The simplest approach is to just iterate over every attribute in a feature:

var fieldInfos = []
var attributes = {}

for (var att in $feature) {
	if (!IsEmpty($feature[att])) {
		Push(fieldInfos, {fieldName: att})
		attributes[att] = $feature[att]
	}
}

return {
    type: 'fields',
    title: 'An Expression to Skip Nulls',
    fieldInfos,
    attributes
  }

 

Here it is in action, with a regular fields list to show it working:

jcarlson_0-1702393939164.png

 

jcarlson_1-1702393955012.png

If you have certain fields you want to skip, you can code those in, too. It sounds like there are a lot of attributes you want to catch, so I don't know if it's going to be faster to grab *everything* and then remove ones you don't want, or to manually define the list of attributes you do want. But this should get you started.

- Josh Carlson
Kendall County GIS
KenBuja
MVP Esteemed Contributor

I noticed that your code doesn't show the field aliases (if they are present). Here's a modification that shows them.

var fieldInfos = []
var attributes = {}
var fields = Schema($feature).fields

for (var att in $feature) {
  if (!IsEmpty($feature[att])) {
    var alias = att;
    for (var i in fields){
      if (fields[i].name == att) alias = fields[i].alias
    }
    Push(fieldInfos, {fieldName: alias})
    attributes[alias] = $feature[att]
  }
}

return {
  type: 'fields',
  title: 'An Expression to Skip Nulls',
  fieldInfos,
  attributes
 }

 

jcarlson
MVP Esteemed Contributor

Good addition!

- Josh Carlson
Kendall County GIS
temprobertcottreau131313
Occasional Contributor II

I have a layer with about 50 fields that show up as 50 rows in the popup.  Most of these are Null values.

Is there a way to create an expression that will set it up to not show the fields with Null values in the popup without typing 50 expressions?

I've seen HTML solutions and ideas for Map Viewer Classic but I'm using the New Map Viewer.

Thanks to all.

Tags (3)
0 Kudos
BlairMcclenathan
New Contributor III

This is how I've accomplished this, its a little manual since you have to add the fields induvial but it loads quickly and works well for our applications (add an arcade element then add the code to that):

 

var fieldInfos = []

if (!IsEmpty (Trim($feature.facilityid))) {
    Push (fieldInfos, {fieldName: 'FacilityID', label: 'Facility Identifier'})
};

if (!IsEmpty (Trim($feature.ownedby))) {
    Push (fieldInfos, {fieldName: 'Owned By', label: 'Owned By'})
};

if (!IsEmpty (Trim($feature.presentstatus))) {
    Push (fieldInfos, {fieldName: 'Present Status', label: 'Present Status'})
};

if (!IsEmpty (Trim($feature.comment))) {
    Push (fieldInfos, {fieldName: 'Comment', label: 'Comment'})
};

if (!IsEmpty (Trim($feature.flowtestcomplete))) {
    Push (fieldInfos, {fieldName: 'Flow Test Complete', label: 'Flow Test Complete'})
};

if (!IsEmpty (Trim($feature.inspectionResult))) {
    Push (fieldInfos, {fieldName: 'Inspection Result', label: 'Inspection Result'})
};

if (!IsEmpty (Trim($feature.flowtestcomment))) {
    Push (fieldInfos, {fieldName: 'Flow Test Comment', label: 'Flow Test Comment'})
};

if (!IsEmpty (Trim($feature.flow))) {
    Push (fieldInfos, {fieldName: 'Flow Rate', label: 'Flow Rate'})
};

if (!IsEmpty (Trim($feature.flushingzone))) {
    Push (fieldInfos, {fieldName: 'Flushing Zone', label: 'Flushing Zone'})

};

if (!IsEmpty (Trim($feature.firestation))) {
    Push (fieldInfos, {fieldName: 'Fire Station District', label: 'Fire Station District'})

};

if (!IsEmpty (Trim($feature.lastflowtest))) {
    Push (fieldInfos, {fieldName: 'Last Flow Test', label: 'Last Flow Test'})

};

return {
    type: 'fields',
    fieldInfos: fieldInfos,
    attributes: {
        'FacilityID': $feature.facilityid,
        'Owned By': DomainName($feature, "ownedby"),
        'Present Status': DomainName($feature, "presentstatus"),
        'Comment': $feature.comment,
        'Flow Test Complete': DomainName($feature, "flowtestcomplete"),
        'Flow Test Comment': $feature.flowtestcomment,
        'Flow Rate': $feature.flow + ' GPM',
        'Flushing Zone': DomainName($feature, "flushingzone"),
        'Fire Station District': DomainName($feature, "firestation"),
        'Last Flow Test': (month($feature.lastflowtest) + 1) + '/' + day($feature.lastflowtest) + '/' + (Year($feature.lastflowtest)) + ' at ' + Hour($feature.lastflowtest) + ':' + Minute($feature.lastflowtest)
    }
}
0 Kudos
edward33
New Contributor III

@BlairMcclenathan 

Do you know how I would add rounding to this? I tried something like-

'Flow Rate': round($feature.flow, 2)

in the return section but that doesn't seem to do anything.

0 Kudos