Select to view content in your preferred language

Exclude empty field from pop-up with custom order using arcade expression in Field Maps

379
4
Jump to solution
01-28-2026 09:51 PM
range97
Emerging Contributor

Hi there, 

I have fields in my forms that are not relevant/used during every form submission. I would like to exclude empty fields from the popups and always exclude data not relevant to viewer such as OBJECTID, EditDate, Creator, GlobalID, CreationDate, Editor etc. 

I found an expression from another community post and input the fields I wanted excluded: 

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


var excludeFields = ["OBJECTID", "EditDate", "Creator", "GlobalID", "CreationDate", "Editor"];


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 had the intended effect of hiding irrelevant and empty fields.  
 
I need to also control the order in which the returned visible fields are displayed. This expression is currently returning the fields in alphabetical order. I need to have the same three fields displayed at the top of the pop up in the following order for every submission: HMA, Observation Date and Time, and Type. I do not care about the order of the other 5-8 fields that would be displayed. Ideally I would like to order the popup in the same display order of the collector forms. 
 
I am not sure how to proceed. I have tried several alternatives and I am not getting the result I intend. 
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

Thanks for pointing that out. I did leave off the Expects function at the top of the code. All you need to do is add this as the first line

Expects($feature, "*");

View solution in original post

0 Kudos
4 Replies
KenBuja
MVP Esteemed Contributor

To maintain the order of the fields, you have to get the schema of the feature. Try this code, which returns the field alias and domain name (if the field has a domain)

var fields = Schema($feature).fields;

var fieldInfos = [];
var attributes = {};

var excludeFields = [
  "OBJECTID",
  "EditDate",
  "Creator",
  "GlobalID",
  "CreationDate",
  "Editor"
];

for (var field of fields) {
  var key = field.alias;
  var value = DomainName($feature, field.name);
  if (!IsEmpty(value) && value != "" && IndexOf(excludeFields, key) == -1) {
    Push(fieldInfos, { fieldName: key });
    attributes[key] = value;
  }
}
return { type: "fields", fieldInfos: fieldInfos, attributes: attributes };
range97
Emerging Contributor

Thank you for your response! I am still new to using Arcade Expressions. 

When I first tried the expression the pop up window populates with data. After saving and clicking off the current point to a different point on the same layer all the pop ups are blank. The only way I can get the expression to display anything in the popup window now is to have a field list as well as the arcade expression which is now displaying the block of fields from the arcade expression and the field list in a separate block below. If I remove the field list it returns a blank popup window. I think I am doing something wrong. 

Any ideas? When I tried looking for solutions to this blank popup issue it looks like I need to use the Expect function but not sure how I would go about that. 

0 Kudos
KenBuja
MVP Esteemed Contributor

Thanks for pointing that out. I did leave off the Expects function at the top of the code. All you need to do is add this as the first line

Expects($feature, "*");
0 Kudos
range97
Emerging Contributor

Thank you so much for the help! Now it is behaving exactly as I had hoped. I don't think I would have thought to add it to the first line. I had tried it at the end of the string. You have been such a great help, I greatly appreciation for your generosity. Hopefully this also aids someone else. 

0 Kudos