Select to view content in your preferred language

Arcade expression to return HTML text

3435
8
Jump to solution
08-05-2023 01:33 PM
swhitcombMCC
New Contributor III

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>`
  }
}

 

swhitcombMCC_0-1691267416496.png

 

1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

An Arcade expression can't interpret HTML. What you want is an Arcade element.

JohannesLindner_0-1691386327280.png

 

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
}

Have a great day!
Johannes

View solution in original post

8 Replies
JohannesLindner
MVP Frequent Contributor

An Arcade expression can't interpret HTML. What you want is an Arcade element.

JohannesLindner_0-1691386327280.png

 

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
}

Have a great day!
Johannes
loum
by
New Contributor III

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

0 Kudos
JohannesLindner
MVP Frequent Contributor

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).


Have a great day!
Johannes
loum
by
New Contributor III

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

0 Kudos
RyanBohan
Regular Contributor

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.

 

0 Kudos
StaciMcLaughlin
New Contributor II

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.

StaciMcLaughlin_0-1695837320752.png

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.

StaciMcLaughlin_2-1695837935781.png

 

If anyone has any insight or expressions they could share I would appreciate it.

 

Thank you!

 

 

 

0 Kudos
JohannesLindner
MVP Frequent Contributor

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.


Have a great day!
Johannes
StaciMcLaughlin
New Contributor II
##- Thank you! -##
0 Kudos