Select to view content in your preferred language

Using Arcade to return an hyperlink if field is not null

1624
5
Jump to solution
11-29-2023 05:49 AM
Labels (1)
Cyril
by
Emerging Contributor

[Portal 10.9.1] [Arcade expression]

Hello, i added this html code to customize the pop up windows in a Portal app :

<strong>Email : </strong><a href="mailto:{mail}">contact mail</a>

Sans-titre-1

but i figured i had several blank fields (' ') in my Email column... so it result a link wich open outlook but with no email adress

 

So i tried to fix this with an Arcade expression but the result is not really what i need because it return a link even if the email field is null.

var mail = $feature.email;

if (mail == ' ') {
mail = 'no email adress';
}

return mail;

  I know the solution would be to create my link in an other Arcade expression but it seems i'm not able to find out the solution.

The thing i would like is using Arcade to return an hyperlink (mailto: for email) if field is not null

May someone help me with this please ?

Many thanks

Dave

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

A standalone Arcade expression will only return a string, so if you try to include HTML tags, you'll get the literal text "<a href=mailto...>", etc.

To get Arcade to return items that respect HTML tags, you need to use an actual Arcade element in your popup, which is unfortunately not available at 10.9.1.

One way around this is to use an expression to check the presence of an email address, and use that expression to control the visibility on a <div> in your popup text. Here's a relevant post from @JohannesLindner : https://community.esri.com/t5/arcgis-online-questions/using-arcade-or-html-to-hide-display-hyperlink...

The expression could be as simple as:

iif($feature.email == ' ', 'none', 'block')

 

 And the popup formatting (remember to click "show source" first):

<div style="display:{expression/email_visibility}">
<strong>Email : </strong><a href="mailto:{email}">contact mail</a>
</div>

 

- Josh Carlson
Kendall County GIS

View solution in original post

5 Replies
KenBuja
MVP Esteemed Contributor

Is the field empty ('') or does it have spaces (' ')?

You can use the IsEmpty function and incorporate the Trim function if there are one or more spaces.

 

 

var mail = $feature.email;

if (Isempty(Trim(mail))) {
  mail = 'no email adress';
}

return mail;

 

0 Kudos
Cyril
by
Emerging Contributor

Hello KenBuja,

Thanks for your answer.

The field is not null or empty... there is a space in it. My arcade expression work like this but my problem is to generate a mailto link only if i got an email adress.

0 Kudos
jcarlson
MVP Esteemed Contributor

A standalone Arcade expression will only return a string, so if you try to include HTML tags, you'll get the literal text "<a href=mailto...>", etc.

To get Arcade to return items that respect HTML tags, you need to use an actual Arcade element in your popup, which is unfortunately not available at 10.9.1.

One way around this is to use an expression to check the presence of an email address, and use that expression to control the visibility on a <div> in your popup text. Here's a relevant post from @JohannesLindner : https://community.esri.com/t5/arcgis-online-questions/using-arcade-or-html-to-hide-display-hyperlink...

The expression could be as simple as:

iif($feature.email == ' ', 'none', 'block')

 

 And the popup formatting (remember to click "show source" first):

<div style="display:{expression/email_visibility}">
<strong>Email : </strong><a href="mailto:{email}">contact mail</a>
</div>

 

- Josh Carlson
Kendall County GIS
Cyril
by
Emerging Contributor

Hello jcarlson,

 

It works perfectly ! Many thanks.

0 Kudos
AdamRepsher_BentEar
Frequent Contributor

Hi @jcarlson !
I am currently working within Portal 10.9.1 and am not finding something for this workaround.
You say:


@jcarlson wrote:

 And the popup formatting (remember to click "show source" first):


I cannot find "Show Source".  Are you seeing this in a popup within the NEW Web Map in 10.9.1?

Thanks, 

Adam

0 Kudos