I have scoured posts and am unable to find a way to exclude fields that have Null values in pop-ups. I am using Map Viewer, but not opposed to using Map Viewer Classic or even ArcGIS Pro to get this functionality to work.
From what I understand, Arcade is a non-object oriented, JavaScript-based language (please correct me if I'm wrong!).
Here are some code snippets of what I have tried and how they failed.
var popUpContent = "";
var fieldsToInclude = ["objectid", "symbol_group"];
var isFirstIteration = true;
var feat = FeatureSetByName($map, "Wells TVD 20K Grid", fieldsToInclude, false);
Function GetAlias(f, fldname) {
var scheme = Schema(f);
var flds = scheme["fields"];
for (var i in flds) {
var fldinfo = flds[i];
if (fldinfo["name"] == fldname) {
return fldinfo["alias"];
};
};
return fldname;
};
for (var f in feat) {
for (var field in fieldsToInclude) {
var fieldName = fieldsToInclude[field];
if (isFirstIteration){
if (!IsEmpty(f[fieldName]) && f[fieldName] != 0) {
var alias = GetAlias(f, fieldName);
popUpContent += alias + " = " + f[fieldName] + TextFormatting.NewLine;
};
};
};
isFirstIteration = false;
};
return popUpContent;Failure: Not returning the correct attribution data, but it does exclude Null values and Aliases.
var popUpContent = "";
var fieldsToInclude = ["objectid", "symbol_group"];
var isFirstIteration = true;
var feat = FeatureSetByName($map, "Wells TVD 20K Grid", fieldsToInclude, false);
Function GetAlias(f, fldname) {
var esquema = Schema(f);
var flds = esquema["fields"];
for (var i in flds) {
var fldinfo = flds[i];
if (fldinfo["name"] == fldname) {
return fldinfo["alias"];
};
};
return fldname;
};
for (var f in feat) {
var row = {};
for (var field in fieldsToInclude) {
var fieldName = fieldsToInclude[field];
if (!IsEmpty(f[fieldName]) && f[fieldName] != 0) {
var alias = GetAlias(f, fieldName);
row[alias] = f[fieldName];
}
}
return row
}Failure: Not returning the correct attribution data, but it does exclude Null values and Aliases.
var fieldsToInclude = ["tvd_ft_0",
"well_status_type",
"Symbology",
"tvd_ft_bin_count"
];
var features = FeatureSetByName($map, 'Well Status-20K Grid', fieldsToInclude, false);
var aDict = Schema(features);
var aArray = aDict["fields"];
var output;
for (var i in $feature){
if (!IsEmpty($feature[i]) &&
($feature[i] != 0)) {
for(var j in aArray) {
var dict = aArray[j];
if (dict['name'] == i){
output += dict['alias'] + ": " + $feature[i] + TextFormatting.NewLine + TextFormatting.NewLine;
};
};
};
};
return output;Failure: Not returning correct field names/ alisases