<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Formatting an Arcade Expression for Popup in Grid/Table Format in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/formatting-an-arcade-expression-for-popup-in-grid/m-p/1533439#M61271</link>
    <description>&lt;P&gt;Thank you!&amp;nbsp; I will work with this.&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 30 Aug 2024 16:04:55 GMT</pubDate>
    <dc:creator>AllisonWebb</dc:creator>
    <dc:date>2024-08-30T16:04:55Z</dc:date>
    <item>
      <title>Formatting an Arcade Expression for Popup in Grid/Table Format</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/formatting-an-arcade-expression-for-popup-in-grid/m-p/1533392#M61268</link>
      <description>&lt;P&gt;Hello - I need some help with formatting a popup.&amp;nbsp; I want to display my data in a grid format.&amp;nbsp; I'm using the below Arcade expression. How do I add the formatting?&amp;nbsp; I'm new at Arcade and I've tried to find examples online, but not having any luck.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The current result is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AllisonWebb_0-1725030552587.png" style="width: 200px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/113986i02320E3106050DC2/image-size/small?v=v2&amp;amp;px=200" role="button" title="AllisonWebb_0-1725030552587.png" alt="AllisonWebb_0-1725030552587.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Want:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AllisonWebb_1-1725030604036.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/113987i804FFC07169F943C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AllisonWebb_1-1725030604036.png" alt="AllisonWebb_1-1725030604036.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;var harvestLayer = FeatureSetByName($map, "Harvest Tracking v4 Analysis View");&lt;/P&gt;&lt;P&gt;var currentFeatureID = $feature.UCode;&lt;/P&gt;&lt;P&gt;var relatedRecords = Filter(harvestLayer, "BlockCode = @currentFeatureID");&lt;/P&gt;&lt;P&gt;var result = "";&lt;/P&gt;&lt;P&gt;for (var record in relatedRecords) {&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; var sampleBlockName = record.SampleBlockName;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; var sampleDate = Text(record.SampleDate, "MM/DD/YYYY");&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; var brix = record.Brix;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; result += sampleBlockName + " " + sampleDate + " " + brix + TextFormatting.NewLine;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;// Return the result&lt;/P&gt;&lt;P&gt;return result;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Aug 2024 15:15:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/formatting-an-arcade-expression-for-popup-in-grid/m-p/1533392#M61268</guid>
      <dc:creator>AllisonWebb</dc:creator>
      <dc:date>2024-08-30T15:15:01Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting an Arcade Expression for Popup in Grid/Table Format</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/formatting-an-arcade-expression-for-popup-in-grid/m-p/1533421#M61270</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/588041"&gt;@AllisonWebb&lt;/a&gt;&amp;nbsp;Here is an example that we use, hopefully you can pull from it what you would need:&lt;/P&gt;&lt;P&gt;Here is the resulting popup:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ArmstKP_0-1725032122224.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/113998i2F257915A50D5A11/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ArmstKP_0-1725032122224.png" alt="ArmstKP_0-1725032122224.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;&amp;lt;div style="background-color:{expression/expr0};color:#FFFFFF;padding:7px;text-align:center;"&amp;gt;
    &amp;lt;span style="font-size:medium;"&amp;gt;{expression/expr1}&amp;lt;/span&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;figure class="table" style="width:100%;"&amp;gt;
    &amp;lt;table style="border-collapse:collapse;font-family:arial, sans-serif;text-align:left;"&amp;gt;
        &amp;lt;tbody&amp;gt;
            &amp;lt;tr style="background-color:#eee;"&amp;gt;
                &amp;lt;td style="border:1px solid #ddd;padding:8px;"&amp;gt;
                    Fountain Type
                &amp;lt;/td&amp;gt;
                &amp;lt;td style="border:1px solid #ddd;padding:8px;"&amp;gt;
                    {Type}
                &amp;lt;/td&amp;gt;
            &amp;lt;/tr&amp;gt;
            &amp;lt;tr&amp;gt;
                &amp;lt;td style="border:1px solid #ddd;padding:8px;"&amp;gt;
                    Dog Dish
                &amp;lt;/td&amp;gt;
                &amp;lt;td style="border:1px solid #ddd;padding:8px;"&amp;gt;
                    {dog_dish}
                &amp;lt;/td&amp;gt;
            &amp;lt;/tr&amp;gt;
            &amp;lt;tr style="background-color:#eee;"&amp;gt;
                &amp;lt;td style="border:1px solid #ddd;padding:8px;"&amp;gt;
                    Spout
                &amp;lt;/td&amp;gt;
                &amp;lt;td style="border:1px solid #ddd;padding:8px;"&amp;gt;
                    {spout_type}
                &amp;lt;/td&amp;gt;
            &amp;lt;/tr&amp;gt;
            &amp;lt;tr&amp;gt;
                &amp;lt;td style="border:1px solid #ddd;padding:8px;"&amp;gt;
                    Last Update
                &amp;lt;/td&amp;gt;
                &amp;lt;td style="border:1px solid #ddd;padding:8px;"&amp;gt;
                    {expression/expr2}
                &amp;lt;/td&amp;gt;
            &amp;lt;/tr&amp;gt;
        &amp;lt;/tbody&amp;gt;
    &amp;lt;/table&amp;gt;
&amp;lt;/figure&amp;gt;&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 30 Aug 2024 15:36:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/formatting-an-arcade-expression-for-popup-in-grid/m-p/1533421#M61270</guid>
      <dc:creator>ArmstKP</dc:creator>
      <dc:date>2024-08-30T15:36:01Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting an Arcade Expression for Popup in Grid/Table Format</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/formatting-an-arcade-expression-for-popup-in-grid/m-p/1533439#M61271</link>
      <description>&lt;P&gt;Thank you!&amp;nbsp; I will work with this.&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Aug 2024 16:04:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/formatting-an-arcade-expression-for-popup-in-grid/m-p/1533439#M61271</guid>
      <dc:creator>AllisonWebb</dc:creator>
      <dc:date>2024-08-30T16:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting an Arcade Expression for Popup in Grid/Table Format</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/formatting-an-arcade-expression-for-popup-in-grid/m-p/1533444#M61272</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/588041"&gt;@AllisonWebb&lt;/a&gt;&amp;nbsp;This example is a little more advanced, but I thought you could use this example to build out yours.&amp;nbsp; You have to add this code with the Arcade popup element:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ArmstKP_0-1725034108853.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/114004i1DF13E156266ACF9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ArmstKP_0-1725034108853.png" alt="ArmstKP_0-1725034108853.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Resulting popup:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ArmstKP_1-1725034162846.png" style="width: 484px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/114005i0B4C8D5C3ECEE7E9/image-dimensions/484x351?v=v2" width="484" height="351" role="button" title="ArmstKP_1-1725034162846.png" alt="ArmstKP_1-1725034162846.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// Function to get background color and text color based on status
function getBackgroundColorAndTextColor(status) {
    var color = iif(status == "Open", "#2DA13C", 
               iif(status == "Closed" || status == "Closed Bacteria Levels", "#FF0000", "#FFB22E"));
    return {
        backgroundColor: color,
        textColor: "#FFFFFF" // Default to white text
    };
}

// Get colors for the status
var colors = getBackgroundColorAndTextColor($feature.status);

// Define the header text
var headerText = "Pool/Splash Pad is " + Text($feature.status);

// Get the GlobalId of the selected feature
var globalId = $feature.GlobalId;

// Create a FeatureSet from the related records service
var relatedRecords = FeatureSetByPortalItem(
    Portal("https://www.arcgis.com"), 
    "XXXXXXXXXXXXXXXXXXXX", 
    0, 
    ["*"] // Retrieve all fields
);

// Filter the related records by matching the GlobalId
var filteredRecords = Filter(relatedRecords, "relfeatureglobalid = @globalId");

// Sort the filtered records by sample_date in descending order
var sortedRecords = OrderBy(filteredRecords, 'sample_date DESC');

// Limit to the last three records
var lastThreeRecords = Top(sortedRecords, 3);

// Initialize a string to build the formatted output
var rows = "";
var recordCount = Count(lastThreeRecords);

// Loop through each of the last three records and build the output string
if (recordCount &amp;gt; 0) {
    for (var record in lastThreeRecords) {
        // Check if the status is "Not Acceptable" and set the background color accordingly
        var rowBackgroundColor = "";
        if (record.status == "Not Acceptable") {
            rowBackgroundColor = "background-color: #FBDCDC;";
        }
        rows += "&amp;lt;tr style='" + rowBackgroundColor + "'&amp;gt;";
        rows += "&amp;lt;td style='border: 1px solid lightgrey; padding: 8px; font-size: 12px;'&amp;gt;" + Text(record.sample_date, 'MMM D Y') + "&amp;lt;/td&amp;gt;";
        rows += "&amp;lt;td style='border: 1px solid lightgrey; padding: 8px; font-size: 12px;'&amp;gt;" + record.ecoli + "&amp;lt;/td&amp;gt;";
        rows += "&amp;lt;td style='border: 1px solid lightgrey; padding: 8px; font-size: 12px;'&amp;gt;" + record.enterococci + "&amp;lt;/td&amp;gt;";
        rows += "&amp;lt;td style='border: 1px solid lightgrey; padding: 8px; font-size: 12px;'&amp;gt;" + record.p_aeruginosa + "&amp;lt;/td&amp;gt;";
        rows += "&amp;lt;td style='border: 1px solid lightgrey; padding: 8px; font-size: 12px;'&amp;gt;" + record.water_temp + "°F" + "&amp;lt;/td&amp;gt;";
        rows += "&amp;lt;td style='border: 1px solid lightgrey; padding: 8px; font-size: 12px;'&amp;gt;" + record.status + "&amp;lt;/td&amp;gt;";
        rows += "&amp;lt;/tr&amp;gt;";
    }
}

// Combine all parts into a single HTML string
var popupContent = "&amp;lt;div style='display: flex; align-items: center; margin-bottom: 10px;'&amp;gt;";
popupContent += "&amp;lt;img src='https://uxwing.com/wp-content/themes/uxwing/download/brands-and-social-media/google-map-icon.png' alt='Google Maps' style='width: 20px; height: 20px; margin-right: 5px;'/&amp;gt;";
popupContent += "&amp;lt;a href='https://www.google.com/maps/dir/?api=1&amp;amp;destination={expression/expr3},{expression/expr4}' target='_blank'&amp;gt;Google Maps Directions&amp;lt;/a&amp;gt;";
popupContent += "&amp;lt;/div&amp;gt;";
popupContent += "&amp;lt;h3 style='text-align:center; background-color: " + colors.backgroundColor + "; color: " + colors.textColor + "; padding: 7px;'&amp;gt;" + headerText + "&amp;lt;/h3&amp;gt;";
popupContent += "&amp;lt;div style='padding: 7px;'&amp;gt;";
popupContent += "&amp;lt;table style='width:100%; border-collapse: collapse; font-family:arial, sans-serif;'&amp;gt;";
popupContent += "&amp;lt;tbody&amp;gt;";
popupContent += "&amp;lt;tr style='background-color:#eee;'&amp;gt;&amp;lt;td style='border: 1px solid lightgrey; padding: 8px;'&amp;gt;Pool Type&amp;lt;/td&amp;gt;&amp;lt;td style='border: 1px solid lightgrey; padding: 8px;'&amp;gt;" + $feature.Pool_Type + "&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;";

if ($feature.status != "Open") {
    popupContent += "&amp;lt;tr&amp;gt;&amp;lt;td style='border: 1px solid lightgrey; padding: 8px;'&amp;gt;Explanation for Closure&amp;lt;/td&amp;gt;&amp;lt;td style='border: 1px solid lightgrey; padding: 8px;'&amp;gt;" + $feature.public_explanation + "&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;";
    popupContent += "&amp;lt;tr style='background-color:#eee;'&amp;gt;&amp;lt;td style='border: 1px solid lightgrey; padding: 8px;'&amp;gt;Last Status Change&amp;lt;/td&amp;gt;&amp;lt;td style='border: 1px solid lightgrey; padding: 8px;'&amp;gt;" + Text($feature.LastDateInspected, 'MMM D Y, h:mm A') + "&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;";
} else {
    popupContent += "&amp;lt;tr&amp;gt;&amp;lt;td style='border: 1px solid lightgrey; padding: 8px;'&amp;gt;Last Status Change&amp;lt;/td&amp;gt;&amp;lt;td style='border: 1px solid lightgrey; padding: 8px;'&amp;gt;" + Text($feature.LastDateInspected, 'MMM D Y, h:mm A') + "&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;";
}

popupContent += "&amp;lt;/tbody&amp;gt;";
popupContent += "&amp;lt;/table&amp;gt;";
popupContent += "&amp;lt;/div&amp;gt;";

// Check if there are related records before adding the water quality data section
if (recordCount &amp;gt; 0 &amp;amp;&amp;amp; rows != "") {
    popupContent += "&amp;lt;br&amp;gt;&amp;lt;hr style='margin: 10px 0; border: 0; border-top: 1px solid #FF0000;'&amp;gt;"; // Ensure the color change here
    popupContent += "&amp;lt;h3 style='text-align:center; color: #000000; font-size: 16px; padding: 7px; margin-top: 0;'&amp;gt;Water Quality Data&amp;lt;/h3&amp;gt;";
    popupContent += "&amp;lt;div style='text-align:center; margin-top: 10px;'&amp;gt;&amp;lt;a href='https://www.minneapolisparks.org/activities-events/water-activities/webber_natural_swimming_pool/' target='_blank'&amp;gt;Bacteria Levels Explanation (select the water quality tab)&amp;lt;/a&amp;gt;&amp;lt;/div&amp;gt;";
    popupContent += "&amp;lt;div style='padding: 7px;'&amp;gt;";
    popupContent += "&amp;lt;table style='width:100%; border-collapse: collapse; font-family:arial, sans-serif;'&amp;gt;";
popupContent += "&amp;lt;thead&amp;gt;";
popupContent += "&amp;lt;tr style='background-color:#eee; color:#000;'&amp;gt;&amp;lt;th style='border: 1px solid lightgrey; padding: 8px; font-size: 12px;'&amp;gt;Sample Date&amp;lt;/th&amp;gt;&amp;lt;th style='border: 1px solid lightgrey; padding: 8px; font-size: 12px;'&amp;gt;E. coli (mpn)&amp;lt;/th&amp;gt;&amp;lt;th style='border: 1px solid lightgrey; padding: 8px; font-size: 12px;'&amp;gt;Enterococci (mpn)&amp;lt;/th&amp;gt;&amp;lt;th style='border: 1px solid lightgrey; padding: 8px; font-size: 12px;'&amp;gt;P. aeruginosa (mpn)&amp;lt;/th&amp;gt;&amp;lt;th style='border: 1px solid lightgrey; padding: 8px; font-size: 12px;'&amp;gt;Water Temp&amp;lt;/th&amp;gt;&amp;lt;th style='border: 1px solid lightgrey; padding: 8px; font-size: 12px;'&amp;gt;Status&amp;lt;/th&amp;gt;&amp;lt;/tr&amp;gt;";
popupContent += "&amp;lt;/thead&amp;gt;";
popupContent += "&amp;lt;tbody&amp;gt;";
popupContent += rows;
popupContent += "&amp;lt;/tbody&amp;gt;";
popupContent += "&amp;lt;/table&amp;gt;";
popupContent += "&amp;lt;/div&amp;gt;";
}

// Add download links for the specific GlobalIds
var downloadLinks = {
    "{073B88FB-1C1B-4DD2-A29F-F37F781B1DFE}": "https://www.arcgis.com/sharing/rest/content/items/975ba2b7a6be4189be97472852054c0b/data",
    "{46BF0FBE-5887-4201-BC1E-65C0008EBDD5}": "https://www.arcgis.com/sharing/rest/content/items/4be02c90557a4132bb622153461ff8f1/data"
};

if (HasKey(downloadLinks, globalId)) {
    popupContent += "&amp;lt;div style='text-align:center; margin-top: 10px;'&amp;gt;&amp;lt;a href='" + downloadLinks[globalId] + "' target='_blank'&amp;gt;Download This Year's Water Quality Data (CSV)&amp;lt;/a&amp;gt;&amp;lt;/div&amp;gt;";
}

return {
    "type": "text",
    "text": popupContent
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Aug 2024 16:10:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/formatting-an-arcade-expression-for-popup-in-grid/m-p/1533444#M61272</guid>
      <dc:creator>ArmstKP</dc:creator>
      <dc:date>2024-08-30T16:10:58Z</dc:date>
    </item>
  </channel>
</rss>

