Exclude fields that have null values in ArcGIS Dashboard list

788
1
03-10-2023 05:50 AM
Labels (1)
AustinWolf1994
New Contributor

Hello All,

I am working on generating a dashboard based off a table that is updated by Survey 123. Not all fields are going to be used in each submission. I want to put together a list view that shows each submission, but I want to exclude any fields that return a null value in a specific record ({BendMaterials}, and {BlowoffMaterials} in the attached image). Can this be done in Advanced Formatting using an Arcade Expression?

Note - I don't want to fully filter out the table under the data tab of this element. There will be submissions that have null values for these two fields, but will have other important information that needs to show up on this list.

Dashboard List - Dummy Data.png

0 Kudos
1 Reply
jcarlson
MVP Esteemed Contributor

When an attribute occupies a single line of your line item template, nulls are genuinely skipped.

jcarlson_0-1678458024240.png

The trouble is that you're preceding your attributes with text, so that text will always show up. In order to get that text to be dynamic as well, it needs to be driven by an expression. You can do this with the advanced formatting.

I'll change my example to include additional text:

jcarlson_1-1678458127966.png

In general, you want an expression that returns the label and the value if there is one, but nothing if there isn't. That could look like this:

var text_A = iif(IsEmpty($datapoint['A']), '', `Field A: ${$datapoint['A']}`)

Then have your line item consist of things like {expression/text_A} instead of directly accessing the fields. But re-typing all that for each field could be annoying and tedious, especially if it's a long list of fields.

Here's a more advanced method that could apply to a list of fields as long as you want, and will handle the building of the string and pulls in the field alias.

// get schema
var fields = Schema($datapoint)['fields']

// empty array for our output string
var out_arr = []

// list field names that we want in the output text
var out_fields = [
  'A',
  'B',
  'C',
  'D'
]

// function for returning alias
function get_alias(fieldname, fields) {
  for (var f in fields) {
    if (fields[f]['name'] == fieldname) {
      return fields[f]['alias']
    }
  }
}

/*
for each field in that list, we will

1. check to see if the value is present
2. if present, grab the value and the field alias
3. add the two to our output array

after that, we'll concatenate that array into a single string
*/

for (var f in out_fields) {
  if (!IsEmpty($datapoint[out_fields[f]])) {
    var a = get_alias(out_fields[f], fields)
    Push(out_arr, `${a}: ${$datapoint[out_fields[f]]}`)
  }
}

var out_str = Concatenate(out_arr, '<br>')

return {
  attributes: {
    out_str
  }
}

And by entering {expression/out_str} in my list item template, I get this:

jcarlson_2-1678459982965.png

 

- Josh Carlson
Kendall County GIS
0 Kudos