Select to view content in your preferred language

Create dynamic map pop-up with only answered fields from Survey123

126
3
Jump to solution
Monday
EricDilley
New Contributor

I have a survey I created using Survey123 that has over 100 individual questions.  In the survey, most of the questions are folded into others such that filling out the survey only results in filling out at most 20 of the 100 plus fields.  This makes the pop-up for each survey submission on the web map super long and tedious.

Ideally, I would like to create some type of dynamic Arcade code (or any other workaround) that removes fields from the pop-up that were unanswered (have NULL values).  Because I have so many fields, it would be extremely tedious to write if statements for each field.  Are there any developments in the works or known solutions that would allow for removal of all unanswered fields (questions) from the pop-up to reduce its length?  The idea is I want all answered fields to be visible in the pop-up but nothing else.  Thank you for any advice or insight and your time.  

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

You can add an Arcade Element to your popup with this code. It loops through each field in the feature and returns only the fields that contain a value. This also includes a variable (exceptedFields) that contains fields you don't want to show in the field list. Note that those field names are case sensitive.

Expects($feature, "*");

var fields = Schema($feature).fields;

var attributes = {};
var fieldInfos = [];
var exceptedFields = ["OBJECTID", "GlobalID"]; //case sensitive!
for (var f of fields) {
  if (!Includes(exceptedFields, f.name)) {
    if (Trim($feature[f.name]) != "") {
      attributes[f.alias] = $feature[f.name];
      Push(fieldInfos, { fieldName: f.alias });
    }
  }
}

return { type: "fields", fieldInfos: fieldInfos, attributes: attributes };

 

View solution in original post

3 Replies
KenBuja
MVP Esteemed Contributor

You can add an Arcade Element to your popup with this code. It loops through each field in the feature and returns only the fields that contain a value. This also includes a variable (exceptedFields) that contains fields you don't want to show in the field list. Note that those field names are case sensitive.

Expects($feature, "*");

var fields = Schema($feature).fields;

var attributes = {};
var fieldInfos = [];
var exceptedFields = ["OBJECTID", "GlobalID"]; //case sensitive!
for (var f of fields) {
  if (!Includes(exceptedFields, f.name)) {
    if (Trim($feature[f.name]) != "") {
      attributes[f.alias] = $feature[f.name];
      Push(fieldInfos, { fieldName: f.alias });
    }
  }
}

return { type: "fields", fieldInfos: fieldInfos, attributes: attributes };

 

EricDilley
New Contributor

Thank you KenBuja!  This worked perfectly just as I wanted!  Just one thing to note for anyone who comes upon this thread, you add this to the pop-up by clicking on "Add content" and then selecting an "Arcade".  You then copy the above code into the Arcade expression window and then you are good to go!

0 Kudos