I am currently working with Survey123 and ArcGIS Online to manage and display code violations linked to address points. My setup consists of:
A related table that stores violations associated with each address, including inspection dates, statuses, and images as attachments.
Using Arcade expressions, I have successfully pulled attribute data from the related table into the main feature layer. Specifically, I have retrieved:
✅ The Date of the Last Inspection
✅ The Status of the Last Inspection
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.)
Working Scripts for Attribute Retrieval
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: These scripts have been adapted based on Esri’s community resources and documentation.
1. Date of Last Inspection
This script finds the most recent inspection date by ordering the related records in descending order and selecting the latest entry.
var relatedRecords = OrderBy(FeatureSetByRelationshipName($feature, "Related Violations"), "Date_Reported DESC");
var cnt = Count(relatedRecords);
var relatedInfo = "";
if (cnt > 0) {
var info = First(relatedRecords);
relatedInfo = Text(ToLocal(info.Date_Reported), "MM/DD/YYYY");
}
return relatedInfo;
2. Status of Last Inspection
This script retrieves the latest status of the most recent violation by ordering records and selecting the first entry.
var relatedRecords = OrderBy(FeatureSetByRelationshipName($feature, "Related Violations"), "Status DESC");
var cnt = Count(relatedRecords);
var status = "";
if (cnt > 0) {
var info = First(relatedRecords);
status = DefaultValue(info.Status, "Unknown");
}
return status;
Now, I am trying to retrieve and display images (attachments) from the related table within the pop-up of the main feature layer.
To test if I could access the attachments, I used the following script:
var relatedRecords = FeatureSetByRelationshipName($feature, "Related Violations");
var attachmentCount = 0;
for (var record in relatedRecords) {
var attachments = Attachments(record);
attachmentCount += Count(attachments);
}
return attachmentCount;
This successfully confirmed that:
✅ The related table is accessible.
✅ Attachments exist in the related table.
Request for Assistance
I now need guidance on modifying my script to:
Has anyone successfully implemented this in Arcade for ArcGIS Online? Any examples, best practices, or insights would be greatly appreciated!
Thank you in advance!
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.
Someone on this post created a feature service they were storing tokens in as a work around, but obviously this is not the greatest in terms of security.