Select to view content in your preferred language

Issue with Arcade Expression in Popup: Fields Only Displayed When Field List is Included

251
2
Jump to solution
a month ago
Labels (1)
GuyNizry
Occasional Contributor II

Hello everyone,

I'm encountering an issue with an Arcade expression in the Popup window of a feature layer. My goal is to display selected fields in an HTML table format within the Popup, only showing fields that have values and omitting those without values.

The Arcade expression works perfectly and displays fields with values while hiding those without. However, this functionality only works if I include a Field list component in the Popup with those selected fields. If I remove the Field list component or any of the selected fields from the component, the resulting HTML table from the Arcade expression does not display correctly, or it doesn't show the fields that are not in the Field list component.

The idea was to display only the result table from the Arcade expression in the Popup window, showing fields with values, without duplicating fields by having a Field list component that includes fields with no values.

Has anyone else encountered this issue? Does anyone have a solution or workaround for this problem?

Here is the Arcade expression I am using:

 

var fieldNames = [
    "Treatment", "TreatmentActivityType", "WPFSWorkEssence", "ExecutionStatus", 
    "WorkYear", "OriginalWorkYear", "Date", "ReporterName", "DistrictName", 
    "RegionName", "FOR_NO", "FOR_Name", "Stands", "TreatmentUnitAreaDunam", 
    "BuildWPSFMethod", "InvasiveSpecies", "InvasionPattern", "InvasionInfectionLevel", 
    "InvasionInfectionSourceNeighbor", "AgeGr", "ForAgeComposition", "CurForestType", 
    "CurDensity", "CurCover", "ForStatusMain", "ForStatusSecondary", "ForVitality", 
    "AreaDesignation", "ReqForestType", "ThinningPurpose", "OtherThinningPurpose", 
    "TRTPriority", "ThinIntensity", "ThinType", "PruningType", "InvasionTrtNo", 
    "InvasionTrtMechanic", "InvasionTrtChemical", "InvasionTrtDate", "BurnPermission", 
    "WPFSRejectApproveReason", "WPFSRoundName", "BufferZoneType", "AnnualsTRT", 
    "LineInfrastructureType", "Comments"
];

var fieldAliases = [
    "נושא", "תת נושא", "מהות העבודה", "סטטוס ביצוע", "תוכנית עבודה לשנת", 
    "שנת תכנון מקורית", "תאריך", "ממלא הטופס", "מרחב", "שם אזור", 
    "מספר יער", "שם יער", "חלקות עומדים", "שטח היחידה בדונם", "שיטת בניית יחידת העבודה", 
    "מין צמח פולש", "דפוס פלישה", "רמת נגיעות", "מקור הדבקה שכן", 
    "גיל השכבה המטופלת", "מספר שכבות היער", "תצורת צומח יערנית קיימת", 
    "צפיפות קיימת", "כיסוי צמרות קיים", "מצב יער עיקרי", "מצב יער משני", 
    "חיוניות היער", "ייעוד השטח", "תצורת צומח מתקבלת", "מטרת עיקרית", 
    "מטרה משנית", "סדר עדיפות לביצוע", "עוצמת דילול", "אופי דילול", 
    "אופי גיזום", "טיפול מספר", "טיפול מכני", "טיפול כימי", "מועד טיפול רצוי", 
    "האם תנאי שטח מצריכים בקשה לשריפת גזם", "סיבה לדחיית האישור", "סבב הבקשה", 
    "סוג אזור חייץ", "טיפול בקומת הקרקע", "סוג תשתית", "הערות"
];

var html = "<div style='direction: rtl; font-family: Segoe UI;'><div style='background-color: lightgrey; font-weight: bold; font-size: 14px; text-align: center; padding: 5px;'>מאפייני היחידה</div><table style='width:100%; border-collapse: collapse; font-size: 12px;'>";
var stripe = false;

for (var i = 0; i < Count(fieldNames); i++) {
    var key = fieldNames[i];
    var alias = fieldAliases[i];
    if (HasKey($feature, key)) {
        var value = $feature[key];
        if (!IsEmpty(value)) {
            var displayValue = value;
            if (key == "Date") {
                displayValue = Text(Date(value), 'DD/MM/YYYY');
            }
            if (key == "TreatmentUnitAreaDunam") {
                displayValue = Text(Round(Number(value), 1), '#,##0.0'); // Format to one decimal place
            } else {
                displayValue = Replace(displayValue, "_", " "); // Replacing underscores with spaces
            }
            var rowColor = IIf(stripe, "#EDEDED", "#FBFBFB"); // Using the specified colors
            html += "<tr style='background-color:" + rowColor + ";'><td style='border-right: 1px solid #ddd; padding: 8px;'>" + alias + "</td><td style='padding: 8px;'>" + displayValue + "</td></tr>";
            stripe = !stripe;
        }
    }
}

html += "</table></div>";

return {
    type: "text",
    text: html
};

 

 

Part of the resulted table in the popup:

GuyNizry_1-1720238872309.png

Thank you in advance for your assistance!

 

0 Kudos
1 Solution

Accepted Solutions
bbollin
Esri Contributor

Hi @GuyNizry it looks like you need to use the Expects() function here. The Arcade documentation explains this further https://developers.arcgis.com/arcade/function-reference/feature_functions/#expects

View solution in original post

0 Kudos
2 Replies
bbollin
Esri Contributor

Hi @GuyNizry it looks like you need to use the Expects() function here. The Arcade documentation explains this further https://developers.arcgis.com/arcade/function-reference/feature_functions/#expects

0 Kudos
GuyNizry
Occasional Contributor II

Hi @bbollin,

Thank you so much for your suggestion to use the Expects() function. I followed the documentation you provided, and it indeed resolved the issue. I am very grateful for your assistance and quick response.

Best regards,
Guy Nizry