Using Arcade to display image attachment in pop-up

198
2
10-29-2021 04:23 AM
adrianmoisey1
New Contributor

Hi, I am hoping someone can help me here, I am fairly new to Arcade. 

I am trying to use arcade to show an image attachment in a pop-up in AGOL.

I can get it to work ok using the code below as long as all features have an attachment.

var Part1 = "https://services8.arcgis.com/OxmrsInax8iIPqdy/arcgis/rest/services/Civils_Data_Collection/FeatureSer..."

var ObjectID = $feature.OBJECTID

var Part2 = "/attachments/"

var AttachID = First(Attachments($feature)).ID

var Token = "?token=I HAVE REMOVED THIS.

return Part1 + ObjectID + Part2 + AttachID + Token

 

However, when I come across a feature without an attachment the code returns this.

Execution Error:Runtime Error: Cannot call member method on null. ID

Is there an easy way to deal with these null values?

Thanks in advance.

Tags (3)
0 Kudos
2 Replies
JohannesLindner
MVP Regular Contributor
var attach = Attachments($feature)
if(Count(attach) == 0) {
  return "no attachments"
}
var Part1 = "https://services8.arcgis.com/OxmrsInax8iIPqdy/arcgis/rest/services/Civils_Data_Collection/FeatureSer..."
var ObjectID = $feature.OBJECTID
var Part2 = "/attachments/"
var AttachID = First(attach).ID
var Token = "?token=I HAVE REMOVED THIS.
return Part1 + ObjectID + Part2 + AttachID + Token

Have a great day!
Johannes
adrianmoisey1
New Contributor

Thanks for the reply, I will give it a go. 

Adrian

0 Kudos