I'm using ArcGIS Online, trying to configure a customized pop-up in Arcade. I modified an example I found elsewhere on here in order to get output that looks like the standard Fields table, but with the fields in a different order than they are in the source layer, and with some of them being omitted should they contain no data or a code indicating that there is no data. Testing and debugging as I went was fine, including tests that successfully displayed the first several rows as intended, and the script runs fine in the editor - no errors, expected output format. But when I try clicking on a feature on the map, I wind up with an empty pop-up. Weirdly, if I add an off-the-shelf Fields List underneath it, then the expected custom fields table will render, but only in the sample pop-up displayed in the Map Builder - clicking another feature will make it go right back to pretending the script doesn't exist.
Please note that I'm aware this is something of a hackjob, I'm just trying to meet a deadline, I can pretty it up later. Also, none of this data is sensitive, it's open data.
Here's my code:
var allAttributes = Dictionary($feature)["attributes"];
var attributes = {}
var fieldInfos = [];
var attributeValues = {};
var includeFields = ["County", "Primary_Applicant", "Other_Communities", "Obligation_Year", "Project_Status", "Project_Description", "Magazine_Project_Type", "SEMCOG_TAP_Award", "MDOT_TAP_Award"]
for (var key in includeFields) {
insert(attributes, includeFields[key], allAttributes[includeFields[key]])
}
var layer_schema = Schema($feature);
var fieldAliases = {};
for (var i = 0; i < Count(layer_schema.fields); i++) {
var field = layer_schema.fields[i];
fieldAliases[field.name] = field.alias;
}
var value = null
key = "County"
value = attributes[key]
if (!IsEmpty(value) && value != "") {
var displayName = key; // Default to field name
// Use alias if available
if (HasKey(fieldAliases, key)) {
displayName = fieldAliases[key];
}
Push(fieldInfos, { fieldName: key, label: displayName });
attributeValues[key] = value;
}
key = "Primary_Applicant"
value = attributes[key]
if (!IsEmpty(value) && value != "") {
var displayName = key; // Default to field name
// Use alias if available
if (HasKey(fieldAliases, key)) {
displayName = fieldAliases[key];
}
Push(fieldInfos, { fieldName: key, label: displayName });
attributeValues[key] = value;
}
key = "Other_Communities"
value = attributes[key]
if (!IsEmpty(value) && value != "" && value != "NA") {
var displayName = key; // Default to field name
// Use alias if available
if (HasKey(fieldAliases, key)) {
displayName = fieldAliases[key];
}
Push(fieldInfos, { fieldName: key, label: displayName });
attributeValues[key] = value;
}
key = "Obligation_Year"
value = attributes[key]
if (!IsEmpty(value) && value != "") {
var displayName = key; // Default to field name
// Use alias if available
if (HasKey(fieldAliases, key)) {
displayName = fieldAliases[key];
}
Push(fieldInfos, { fieldName: key, label: displayName });
attributeValues[key] = value;
}
key = "Project_Status"
value = attributes[key]
if (!IsEmpty(value) && value != "") {
var displayName = key; // Default to field name
// Use alias if available
if (HasKey(fieldAliases, key)) {
displayName = fieldAliases[key];
}
var decodedValue = Decode(value, 1, "Obligated", 2, "Complete", "Status Unknown")
Push(fieldInfos, { fieldName: key, label: displayName });
attributeValues[key] = decodedValue;
}
key = "Project_Description"
value = attributes[key]
if (!IsEmpty(value) && value != "") {
var displayName = key; // Default to field name
// Use alias if available
if (HasKey(fieldAliases, key)) {
displayName = fieldAliases[key];
}
Push(fieldInfos, { fieldName: key, label: displayName });
attributeValues[key] = value;
}
key = "Magazine_Project_Type"
value = attributes[key]
if (!IsEmpty(value) && value != "") {
var displayName = key; // Default to field name
// Use alias if available
if (HasKey(fieldAliases, key)) {
displayName = fieldAliases[key];
}
var decodedValue = Decode(value, 1, "Sidewalks and Pedestrian and Bicycle Safety Projects", 2, "Trails and Regional Active Transportation Corridor projects", 3, "Streetscapes, placemaking, and downtown walkability projects", "Type Unknown")
Push(fieldInfos, { fieldName: key, label: "Project Type" });
attributeValues[key] = decodedValue;
}
key = "SEMCOG_TAP_Award"
value = attributes[key]
if (!IsEmpty(value) && value != "" && value != 0) {
var displayName = key; // Default to field name
// Use alias if available
if (HasKey(fieldAliases, key)) {
displayName = fieldAliases[key];
}
Push(fieldInfos, { fieldName: key, label: displayName });
value = Concatenate(['$', value], '', "#,###")
attributeValues[key] = value;
}
key = "MDOT_TAP_Award"
value = attributes[key]
if (!IsEmpty(value) && value != "" && value != 0) {
var displayName = key; // Default to field name
// Use alias if available
if (HasKey(fieldAliases, key)) {
displayName = fieldAliases[key];
}
Push(fieldInfos, { fieldName: key, label: displayName });
value = Concatenate(['$', value], '', "#,###")
attributeValues[key] = value;
}
return {
type: 'fields',
fieldInfos: fieldInfos,
attributes: attributeValues
};