<?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: Combine Arcade statements for pop-up in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/combine-arcade-statements-for-pop-up/m-p/1147663#M44590</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/294341"&gt;@JohannesLindner&lt;/a&gt;&amp;nbsp;-&lt;/P&gt;&lt;P&gt;Thank you for the second expression - it works perfectly and is so short/elegant. I really appreciate your help with this.&lt;/P&gt;</description>
    <pubDate>Thu, 24 Feb 2022 18:50:31 GMT</pubDate>
    <dc:creator>erica_poisson</dc:creator>
    <dc:date>2022-02-24T18:50:31Z</dc:date>
    <item>
      <title>Combine Arcade statements for pop-up</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/combine-arcade-statements-for-pop-up/m-p/1145667#M44464</link>
      <description>&lt;P&gt;Hi -&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to customize some pop-ups to show basic information from related tables. My hosted feature layer is set up so that there is a point layer with a series of 1:M relationships to related tables. Relationships are all based on GlobalID/GUID. There is a public version of the hosted feature layer &lt;A href="https://mass-eoeea.maps.arcgis.com/home/item.html?id=ae306d66da414b7f83f1c7db4284a632" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;I have two separate Arcade statements working properly, however it was not until I started configuring the pop-up that I realized these really should be combined into one expression so that the information returned in the pop-up makes sense.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am unsure of how to combine these. I want to to return either of the statements below based on the "Purpose" from the Road Infrastructure point layer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Return this expression if Pupose = Stream Crossing-B:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Access 'Bridge Inspections' table as a FeatureSet
var portal = Portal("https://www.arcgis.com")
var bridges = FeatureSetByPortalItem(portal,
    "ae306d66da414b7f83f1c7db4284a632", 2, ['Inspection_Date',
    'Condition_Overall', 'Inspector_Initials'])

// Filter related features by using a common attribute
var GLOBALID = $feature.GlobalID
var filterStatement = 'Bridge_GlobalID = @GlobalID'

// Related features as a variable
var relatedData = Filter(bridges, filterStatement)

// Sort related features by newest to oldest
var relatedDataSorted = OrderBy(relatedData, 'Inspection_Date DESC')

// Build the pop-up string by iterating through all related features
var popupString1 = '';

if (Count(relatedDataSorted)&amp;gt;0) {
    // Get the first feature in the sorted FeatureSet
    var f = First(relatedDataSorted);
    
    // Build the pop-up string
    popupString1 = DefaultValue(f.Condition_Overall, 'No Condition Recorded') + " " + Text(f.Inspection_Date, 'MM/DD/YYYY') + " by " + DefaultValue(f.Inspector_Initials, 'No Inspector Recorded')

}       

DefaultValue(popupString1, 'No bridge inspections on record')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Return this expression if Purpose = anything but Stream Crossing-B:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Access 'Culvert Inspections' table as a FeatureSet
var portal = Portal("https://www.arcgis.com")
var culverts = FeatureSetByPortalItem(portal,
    "ae306d66da414b7f83f1c7db4284a632", 1, ['Inspection_Date',
    'Condition_Overall', 'Inspector_Initials'])

// Filter related features by using a common attribute
var GLOBALID = $feature.GlobalID
var filterStatement = 'Culvert_GlobalID = @GlobalID'

// Related features as a variable
var relatedData = Filter(culverts, filterStatement)

// Sort related features by newest to oldest
var relatedDataSorted = OrderBy(relatedData, 'Inspection_Date DESC')

// Build the pop-up string by iterating through all related features
var popupString1 = '';

if (Count(relatedDataSorted)&amp;gt;0) {
    // Get the first feature in the sorted FeatureSet
    var f = First(relatedDataSorted);
    
    // Build the pop-up string
    popupString1 = DefaultValue(f.Condition_Overall, 'No Condition Recorded') + " " + Text(f.Inspection_Date, 'MM/DD/YYYY') + " by " + DefaultValue(f.Inspector_Initials, 'No Inspector Recorded')

}       

DefaultValue(popupString1, 'No culvert inspections on record')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what the pop-up looks like now with the two separate Arcade expressions - you can see how it doesn't make any sense. I'd like to only show the proper expression based on Purpose:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="erica_tefft_0-1645203125622.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/34354iD0899384FBB21865/image-size/medium?v=v2&amp;amp;px=400" role="button" title="erica_tefft_0-1645203125622.png" alt="erica_tefft_0-1645203125622.png" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;erica_tefft_0-1645203125622.png&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know I cannot use Arcade to call another expression, and I am guessing that I need to use some sort of if statement to get this working, but I really do not even know where to start.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be very welcome!&lt;/P&gt;</description>
      <pubDate>Fri, 18 Feb 2022 16:52:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/combine-arcade-statements-for-pop-up/m-p/1145667#M44464</guid>
      <dc:creator>erica_poisson</dc:creator>
      <dc:date>2022-02-18T16:52:13Z</dc:date>
    </item>
    <item>
      <title>Re: Combine Arcade statements for pop-up</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/combine-arcade-statements-for-pop-up/m-p/1146091#M44476</link>
      <description>&lt;P&gt;Easiest way:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;if($feature.Purpose == "Stream Crossing-B") {
  // bridge code except last line
  return DefaultValue(popupString1, "No bridge inspection on record")
}  else {
  // culvert code except last line
  return DefaultValue(popupString1, "No culvert inspection on record")
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Better way: The code for bridges and culverts is the same, only the actual data is different. So you have to abstract the code a little:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Access the inspection table as a FeatureSet
var portal = Portal("https://www.arcgis.com")
var portal_item = "ae306d66da414b7f83f1c7db4284a632"
var layer = IIF($feature.Purpose == "Stream Crossing-B", 2, 1)
var fields = ['Inspection_Date', 'Condition_Overall', 'Inspector_Initials']
var inspection_table = FeatureSetByPortalItem(portal, portal_item, layer, fields)

// Build the filter statement
var GlobalID = $feature.GlobalID
var filterStatement = IIF($feature.Purpose == "Stream Crossing-B", "Bridge", "Culvert") + "_GlobalID = @GlobalID"

// Related features as a variable
var relatedData = Filter(inspection_table, filterStatement)

// Sort related features by newest to oldest
var relatedDataSorted = OrderBy(relatedData, 'Inspection_Date DESC')

// Build the popup string
if(Count(relatedDataSorted) == 0) {
  return 'No culvert inspections on record'
}
var f = First(relatedDataSorted);
return DefaultValue(f.Condition_Overall, 'No Condition Recorded') + " " + Text(f.Inspection_Date, 'MM/DD/YYYY') + " by " + DefaultValue(f.Inspector_Initials, 'No Inspector Recorded')&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 21 Feb 2022 08:30:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/combine-arcade-statements-for-pop-up/m-p/1146091#M44476</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-02-21T08:30:03Z</dc:date>
    </item>
    <item>
      <title>Re: Combine Arcade statements for pop-up</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/combine-arcade-statements-for-pop-up/m-p/1147663#M44590</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/294341"&gt;@JohannesLindner&lt;/a&gt;&amp;nbsp;-&lt;/P&gt;&lt;P&gt;Thank you for the second expression - it works perfectly and is so short/elegant. I really appreciate your help with this.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Feb 2022 18:50:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/combine-arcade-statements-for-pop-up/m-p/1147663#M44590</guid>
      <dc:creator>erica_poisson</dc:creator>
      <dc:date>2022-02-24T18:50:31Z</dc:date>
    </item>
  </channel>
</rss>

