<?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 Pulling Attachments from a Related Table in Arcade (Survey123 &amp;amp; ArcGIS Online) in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/pulling-attachments-from-a-related-table-in-arcade/m-p/1597568#M64085</link>
    <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;Hello GIS Community&lt;DIV class=""&gt;&amp;nbsp;&lt;DIV class=""&gt;&amp;nbsp;&lt;DIV class=""&gt;&lt;FONT size="5" color="#000000"&gt;&lt;STRONG&gt;&lt;STRONG&gt;Project Overview&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;DIV class=""&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am currently working with Survey123 and ArcGIS Online to manage and display code violations linked to address points. My setup consists of:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;A main feature layer that contains address points.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;A related table that stores violations associated with each address, including inspection dates, statuses, and images as attachments.&lt;/P&gt;&lt;P&gt;Using Arcade expressions, I have successfully pulled attribute data from the related table into the main feature layer. Specifically, I have retrieved:&lt;BR /&gt;&lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt; The Date of the Last Inspection&lt;BR /&gt;&lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt; The Status of the Last Inspection&lt;/P&gt;&lt;P&gt;Now, I am attempting to retrieve and display images (attachments) from the related table within the pop-up of the main feature layer. (All data, including attachments, are stored in the related table, and a URL is used in Field Maps to feed the address into Survey123 using the relationship.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;Working Scripts for Attribute Retrieval&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;I am adding these as I hope they will assist others with similar issues. Below are the scripts I am using to extract key information from the related table, that are currently functioning as intended. Please note:&amp;nbsp;These scripts have been adapted based on Esri’s community resources and documentation.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="5"&gt;&lt;SPAN class=""&gt;1. Date of Last Inspection&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;This script finds the most recent inspection date by ordering the related records in descending order and selecting the latest entry.&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;PRE&gt;&lt;SPAN class=""&gt;var relatedRecords = &lt;SPAN class=""&gt;OrderBy(&lt;SPAN class=""&gt;FeatureSetByRelationshipName($feature, &lt;SPAN class=""&gt;"Related Violations"), &lt;SPAN class=""&gt;"Date_Reported DESC");
&lt;SPAN class=""&gt;var cnt = &lt;SPAN class=""&gt;Count(relatedRecords);

&lt;SPAN class=""&gt;var relatedInfo = &lt;SPAN class=""&gt;"";
&lt;SPAN class=""&gt;if (cnt &amp;gt; &lt;SPAN class=""&gt;0) {
    &lt;SPAN class=""&gt;var info = &lt;SPAN class=""&gt;First(relatedRecords);
    relatedInfo = &lt;SPAN class=""&gt;Text(&lt;SPAN class=""&gt;ToLocal(info.&lt;SPAN class=""&gt;Date_Reported), &lt;SPAN class=""&gt;"MM/DD/YYYY");
}

&lt;SPAN class=""&gt;return relatedInfo;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT size="5"&gt;&lt;SPAN class=""&gt;2. Status of Last Inspection&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;This script retrieves the latest status of the most recent violation by ordering records and selecting the first entry.&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;PRE&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;var relatedRecords = &lt;SPAN class=""&gt;OrderBy(&lt;SPAN class=""&gt;FeatureSetByRelationshipName($feature, &lt;SPAN class=""&gt;"Related Violations"), &lt;SPAN class=""&gt;"Status DESC");
&lt;SPAN class=""&gt;var cnt = &lt;SPAN class=""&gt;Count(relatedRecords);

&lt;SPAN class=""&gt;var status = &lt;SPAN class=""&gt;"";
&lt;SPAN class=""&gt;if (cnt &amp;gt; &lt;SPAN class=""&gt;0) {
    &lt;SPAN class=""&gt;var info = &lt;SPAN class=""&gt;First(relatedRecords);
    status = &lt;SPAN class=""&gt;DefaultValue(info.&lt;SPAN class=""&gt;Status, &lt;SPAN class=""&gt;"Unknown");
}

&lt;SPAN class=""&gt;return status;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;HR /&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;DIV class=""&gt;&lt;FONT size="5"&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;&lt;STRONG&gt;Current Challenge: Retrieving Attachments from Related Records&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;DIV class=""&gt;&lt;P&gt;Now, I am trying to retrieve and display images (attachments) from the related table within the pop-up of the main feature layer.&lt;/P&gt;&lt;P&gt;To test if I could access the attachments, I used the following script:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;var relatedRecords = &lt;SPAN class=""&gt;FeatureSetByRelationshipName($feature, &lt;SPAN class=""&gt;"Related Violations");
&lt;SPAN class=""&gt;var attachmentCount = &lt;SPAN class=""&gt;0;

&lt;SPAN class=""&gt;for (&lt;SPAN class=""&gt;var record &lt;SPAN class=""&gt;in relatedRecords) {
    &lt;SPAN class=""&gt;var attachments = &lt;SPAN class=""&gt;Attachments(record);
    attachmentCount += &lt;SPAN class=""&gt;Count(attachments);
}

&lt;SPAN class=""&gt;return attachmentCount;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;This successfully confirmed that:&lt;BR /&gt;&lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt; The related table is accessible.&lt;BR /&gt;&lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt; Attachments exist in the related table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;Request for Assistance&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;I now need guidance on modifying my script to:&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;UL&gt;&lt;LI&gt;Extract attachment URLs from related records.&lt;/LI&gt;&lt;LI&gt;Display these attachments as images within the pop-up of the main feature layer.&lt;/LI&gt;&lt;LI&gt;Ensure that multiple attachments can be displayed if they exist.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Has anyone successfully implemented this in Arcade for ArcGIS Online? Any examples, best practices, or insights would be greatly appreciated!&lt;/P&gt;&lt;P&gt;Thank you in advance!&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Thu, 20 Mar 2025 15:19:02 GMT</pubDate>
    <dc:creator>JustinMcIntyre2</dc:creator>
    <dc:date>2025-03-20T15:19:02Z</dc:date>
    <item>
      <title>Pulling Attachments from a Related Table in Arcade (Survey123 &amp; ArcGIS Online)</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/pulling-attachments-from-a-related-table-in-arcade/m-p/1597568#M64085</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;Hello GIS Community&lt;DIV class=""&gt;&amp;nbsp;&lt;DIV class=""&gt;&amp;nbsp;&lt;DIV class=""&gt;&lt;FONT size="5" color="#000000"&gt;&lt;STRONG&gt;&lt;STRONG&gt;Project Overview&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;DIV class=""&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am currently working with Survey123 and ArcGIS Online to manage and display code violations linked to address points. My setup consists of:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;A main feature layer that contains address points.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;A related table that stores violations associated with each address, including inspection dates, statuses, and images as attachments.&lt;/P&gt;&lt;P&gt;Using Arcade expressions, I have successfully pulled attribute data from the related table into the main feature layer. Specifically, I have retrieved:&lt;BR /&gt;&lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt; The Date of the Last Inspection&lt;BR /&gt;&lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt; The Status of the Last Inspection&lt;/P&gt;&lt;P&gt;Now, I am attempting to retrieve and display images (attachments) from the related table within the pop-up of the main feature layer. (All data, including attachments, are stored in the related table, and a URL is used in Field Maps to feed the address into Survey123 using the relationship.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;Working Scripts for Attribute Retrieval&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;I am adding these as I hope they will assist others with similar issues. Below are the scripts I am using to extract key information from the related table, that are currently functioning as intended. Please note:&amp;nbsp;These scripts have been adapted based on Esri’s community resources and documentation.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="5"&gt;&lt;SPAN class=""&gt;1. Date of Last Inspection&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;This script finds the most recent inspection date by ordering the related records in descending order and selecting the latest entry.&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;PRE&gt;&lt;SPAN class=""&gt;var relatedRecords = &lt;SPAN class=""&gt;OrderBy(&lt;SPAN class=""&gt;FeatureSetByRelationshipName($feature, &lt;SPAN class=""&gt;"Related Violations"), &lt;SPAN class=""&gt;"Date_Reported DESC");
&lt;SPAN class=""&gt;var cnt = &lt;SPAN class=""&gt;Count(relatedRecords);

&lt;SPAN class=""&gt;var relatedInfo = &lt;SPAN class=""&gt;"";
&lt;SPAN class=""&gt;if (cnt &amp;gt; &lt;SPAN class=""&gt;0) {
    &lt;SPAN class=""&gt;var info = &lt;SPAN class=""&gt;First(relatedRecords);
    relatedInfo = &lt;SPAN class=""&gt;Text(&lt;SPAN class=""&gt;ToLocal(info.&lt;SPAN class=""&gt;Date_Reported), &lt;SPAN class=""&gt;"MM/DD/YYYY");
}

&lt;SPAN class=""&gt;return relatedInfo;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT size="5"&gt;&lt;SPAN class=""&gt;2. Status of Last Inspection&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;This script retrieves the latest status of the most recent violation by ordering records and selecting the first entry.&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;PRE&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;var relatedRecords = &lt;SPAN class=""&gt;OrderBy(&lt;SPAN class=""&gt;FeatureSetByRelationshipName($feature, &lt;SPAN class=""&gt;"Related Violations"), &lt;SPAN class=""&gt;"Status DESC");
&lt;SPAN class=""&gt;var cnt = &lt;SPAN class=""&gt;Count(relatedRecords);

&lt;SPAN class=""&gt;var status = &lt;SPAN class=""&gt;"";
&lt;SPAN class=""&gt;if (cnt &amp;gt; &lt;SPAN class=""&gt;0) {
    &lt;SPAN class=""&gt;var info = &lt;SPAN class=""&gt;First(relatedRecords);
    status = &lt;SPAN class=""&gt;DefaultValue(info.&lt;SPAN class=""&gt;Status, &lt;SPAN class=""&gt;"Unknown");
}

&lt;SPAN class=""&gt;return status;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;HR /&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;DIV class=""&gt;&lt;FONT size="5"&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;&lt;STRONG&gt;Current Challenge: Retrieving Attachments from Related Records&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;DIV class=""&gt;&lt;P&gt;Now, I am trying to retrieve and display images (attachments) from the related table within the pop-up of the main feature layer.&lt;/P&gt;&lt;P&gt;To test if I could access the attachments, I used the following script:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;var relatedRecords = &lt;SPAN class=""&gt;FeatureSetByRelationshipName($feature, &lt;SPAN class=""&gt;"Related Violations");
&lt;SPAN class=""&gt;var attachmentCount = &lt;SPAN class=""&gt;0;

&lt;SPAN class=""&gt;for (&lt;SPAN class=""&gt;var record &lt;SPAN class=""&gt;in relatedRecords) {
    &lt;SPAN class=""&gt;var attachments = &lt;SPAN class=""&gt;Attachments(record);
    attachmentCount += &lt;SPAN class=""&gt;Count(attachments);
}

&lt;SPAN class=""&gt;return attachmentCount;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;This successfully confirmed that:&lt;BR /&gt;&lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt; The related table is accessible.&lt;BR /&gt;&lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt; Attachments exist in the related table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;Request for Assistance&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;I now need guidance on modifying my script to:&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;UL&gt;&lt;LI&gt;Extract attachment URLs from related records.&lt;/LI&gt;&lt;LI&gt;Display these attachments as images within the pop-up of the main feature layer.&lt;/LI&gt;&lt;LI&gt;Ensure that multiple attachments can be displayed if they exist.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Has anyone successfully implemented this in Arcade for ArcGIS Online? Any examples, best practices, or insights would be greatly appreciated!&lt;/P&gt;&lt;P&gt;Thank you in advance!&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 20 Mar 2025 15:19:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/pulling-attachments-from-a-related-table-in-arcade/m-p/1597568#M64085</guid>
      <dc:creator>JustinMcIntyre2</dc:creator>
      <dc:date>2025-03-20T15:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling Attachments from a Related Table in Arcade (Survey123 &amp; ArcGIS Online)</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/pulling-attachments-from-a-related-table-in-arcade/m-p/1598543#M64113</link>
      <description>&lt;P&gt;AFAIK you cannot reliably/securely do this. You can build a link from the attributes provided that should, in theory display the attachment. But in practice, trying to get the attachment from the rest service like this requires a token that there is no way of generating in arcade.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Someone on &lt;A href="https://community.esri.com/t5/developers-ideas/arcade-function-to-get-logged-user-token/idi-p/1171408" target="_self"&gt;this post&lt;/A&gt;&amp;nbsp;created a feature service they were storing tokens in as a work around, but obviously this is not the greatest in terms of security.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Mar 2025 15:33:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/pulling-attachments-from-a-related-table-in-arcade/m-p/1598543#M64113</guid>
      <dc:creator>AustinAverill</dc:creator>
      <dc:date>2025-03-24T15:33:23Z</dc:date>
    </item>
  </channel>
</rss>

