I'm trying to get a pop-up to return a photo from a URL (with a link) if the Attachment_URL field is not empty, and a text string if it is empty. I'm using the following code. It returns "No photo available" when appropriate, but instead a photo, it returns a table with the key:value pairs as seen in the photo. How do I get it to return the literal text string and not a table?
var attachment = $feature.Attachment_URL
if (isEmpty(attachment)){
return "No photo available"
} else {
return {
type : "text",
text : `<p>Click the photo to open full size in new tab</p>
<p style="text-align:center;"><a href="${attachment}?size=full">
<img class="image_resized" style="width:100%;" src="${attachment}?size=lg" alt="Photo of ${$feature.Common_Name}"></a></p>`
}
}
Solved! Go to Solution.
An Arcade expression can't interpret HTML. What you want is an Arcade element.
An Arcade element returns a dictionary (which your code does) and can interpret that in different ways, depending on the "type" keyword (see here for different possible types).
We just have to change your code a little bit so that it also returns a dictionary when the url is empty:
var attachment = $feature.Attachment_URL
var result = "No photo available"
if (!isEmpty(attachment)){
result = `<p>Click the photo to open full size in new tab</p>
<p style="text-align:center;"><a href="${attachment}?size=full">
<img class="image_resized" style="width:100%;" src="${attachment}?size=lg" alt="Photo of ${$feature.Common_Name}"></a></p>`
}
return {
type : "text",
text : result
}
An Arcade expression can't interpret HTML. What you want is an Arcade element.
An Arcade element returns a dictionary (which your code does) and can interpret that in different ways, depending on the "type" keyword (see here for different possible types).
We just have to change your code a little bit so that it also returns a dictionary when the url is empty:
var attachment = $feature.Attachment_URL
var result = "No photo available"
if (!isEmpty(attachment)){
result = `<p>Click the photo to open full size in new tab</p>
<p style="text-align:center;"><a href="${attachment}?size=full">
<img class="image_resized" style="width:100%;" src="${attachment}?size=lg" alt="Photo of ${$feature.Common_Name}"></a></p>`
}
return {
type : "text",
text : result
}
If I would like to call just the text (result) variable, what is the syntax? I tried expression/expr0 and it returned both type and text value. Thank you
Just do this in line 10:
return result
Be aware that the code in my answer is for an Arcade element, which needs to return the dictionary. In Arcade expressions, you can return a simple value, but they are limited in what they can display (eg they can't interpret HTML, which was the point of this question).
Thank you for your response and information. You are right, they have limitation to display arcade value in TEXT attribute. My task was to display multi values from multi layers through intersect in an uneven table rows. I ended up create the table in TEXT attribute first to make sure it displays and works fine before move it to ARCADE attribute which I can consume multi values from multiple layers. Thanks again for the insight
This is huge! Thank you @JohannesLindner, you honestly might have just saved me from going with a full JavaScript application. Which has been built, but maintenance if I change departments would be a nightmare.
Hello,
I'm new with configuring Smart Forms, but I am trying to create a calculated expression for an "Inspector Name" field for an asset inspection form I created. I would like to have the inspector's name automatically populate, where it basically pulls from the ArcGIS Account name or their email possiblily.
Luckily I was able to figure out the expression to automatically pull in the Inspection date of when the form was complete with the time, but now I need to determine how I can automatically pull in the user name.
If anyone has any insight or expressions they could share I would appreciate it.
Thank you!
I suggest asking this as a new question, as it doesn't really have anything to do with this question. Plus, your new question will appear on the community feed and attract far more attention.