Select to view content in your preferred language

Arcade to display attachments in popup from another layer in webmap

7551
17
Jump to solution
05-22-2023 10:33 AM
Labels (1)
BeccaSettele
Emerging Contributor

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
17 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

 

Happy mapping,
- Zach
0 Kudos
KeFAnda
Emerging Contributor

Hey Zach,

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

0 Kudos
KeFAnda
Emerging Contributor

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!

 

Danielle_Kuchler
New Contributor

Thank you so much, this helped solve the issue I was having with creating the image url.

0 Kudos
SMH-Rio
Frequent Contributor

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!

Happy mapping,
- Zach
0 Kudos
LledSmith_HDR
New Contributor

I just ran into this question and would like to share my final code.  This code works with a Locaked service using an app token.

var x = Count(Attachments($feature))
var Atts = Attachments($feature)
 var urls = ""
 var Part2 = '/attachments/'
 var AttachID = ""
 var token = "?token=$$$Make an App Token in AGOL and put it here$$$"

If (!isEmpty(Atts)) {
    for (var a in Atts) {
                AttachID =atts[a].id
                urls = Part1 + $feature.OBJECTID + Part2 + AttachID + token + '"><br>' + urls        
    }      
}
return {
    type : 'text',
    text : urls
}
0 Kudos
Sian_Doherty_GHD
Occasional Contributor

Can you please elaborate on how to do this: $$$Make an App Token in AGOL and put it here$$$ so it would work for all users who would be viewing the application? How would the refresh work on that, because don't tokens still expire?


0 Kudos