Select to view content in your preferred language

Arcade to display attachments in popup from another layer in webmap

3307
14
Jump to solution
05-22-2023 10:33 AM
Labels (1)
BeccaSettele
New Contributor II

Hi, 

I have been struggling with showing attachments from one layer into another in a webmap for a bit now and am finally reaching out to the esri community blog gods.

I have two feature layers in a web map ("Beaver Obscured" and "Beaver"). I would like for the attachments in "Beaver" to show up in the popup for "Beaver Obscured". "Beaver Obscured" does not have attachments but does have a shared globalID with "Beaver". Is there a way to take the attachments from "Beaver" and add them to the popup of "Beaver Obscured" in my webmap with arcade? I thought I could do this based on their globalIDs , as I've read through several examples of how to do this with related data but I am struggling to get those scripts to work with shared globalIDs. 

Does anyone have suggestions with arcade, or other work arounds? 

Thanks in advance,
Becca

0 Kudos
14 Replies
ZachBodenner
MVP Regular Contributor

Okay so actually I "figured out" the comma problem by deleting the regualar brackets after Push and then just enter new ones. So there's that. So now I'm very close! I wrote the code as an attribute expression:

// related table layer
var fs = FeatureSetById($map, "189ffea4bbf-layer-175")

// get matching feature based on GlobalID to GUID Relationship
var match = First(Filter(fs, `CompRel = '${$feature['GlobalID']}'`))

console ("fs: "+fs);
console ("match: "+match);

// get matching feature's attachments
var atts = Attachments(match)
console ("atts:" + atts)

// push attachment urls into array
var urls = []

for (var att in atts) {
    Push (urls,`<img src="https://gis.edenprairie.org/maps/rest/services/Internal/CodeViolations/FeatureServer/1/${match['OBJECTID']}/${atts[att]['id']}"></img>`)
}
return Concatenate(urls, '<br>')

 

and then go add that expression into a text section in the popup but just get this:

 

ZachBodenner_0-1692980381781.png

 

0 Kudos
KeFAnda
New Contributor II

Hey Zach,

Have you been able to find a solution for this? It's happening on my end also.

0 Kudos
KeFAnda
New Contributor II

I got it to work!

The URL link was missing the /attachments/ portion in between /${match['objectid']}/${atts[att]['id']}"

KeFAnda_0-1701378640105.png
Hope this helps!

 

0 Kudos
SMH-Rio
New Contributor III

The only problem with this solution is the token issue, right?

I adapted the code to show certain attachments based on their name and everything works fine, except that when I click on the link, it always asks me for an access token (in ArcGIS Online). I have an admin login, I own the layer and the link is exactly the same as when I access the attachment directly in the feature layer (except for the token).

In ArcGIS Enterprise, I can access without the "?token=" in the url.

Is this really the expected behavior or am I missing something? If so, is there no way to automatically generate tokens for the user from Arcade?

0 Kudos
ZachBodenner
MVP Regular Contributor

Oh good to know! I actually abandoned trying after a while, since the project I wanted it for is used exclusively in Field Maps or Experience Builder, and there were some acceptable workarounds. I'll keep this in mind for the future though!

0 Kudos