Using Arcade to create hyperlink based on attribution

6053
11
07-01-2020 07:04 AM
higgy7
by
New Contributor III

Hi,

I am looking at using arcade to create a hyperlink in a popup based on attributes held within the data.

I have created an attribute expression as follows:


IIf($feature["TELEMETRY_MATCH"]=='YES', 'url'+$feature.FULLNAME+'?anotherpieceoftext', 'Currently not linked to telemetry')

I want to continue to use the A list of field attributes option, with the output of this expression:

I have successfully done this but instead of just a string i want the result when 'YES' to be a hyperlink.

Basically i want this to be a hyperlink:

Is this possible? Any help greatly appreciated.

Thanks

Ciaran

Tags (3)
0 Kudos
11 Replies
XanderBakker
Esri Esteemed Contributor

Hi Ciaran Higgins ,

When you return a string that represents a valid url it should be displayed as a link. I notice that you return this:

'url'+$feature.FULLNAME+'?anotherpieceoftext'

Starting the url with a text "url" will not result in a valid url. What is the exact url you try to create?

0 Kudos
higgy7
by
New Contributor III

Hi Xander Bakker,

The url starts http://telemweb/graph/ 

Then it contains the full name contained in the table, then finishes with ?Historic&applet

How do i return it as a link? I made an attempt at using href= but i was unsuccessful. I was able to do it as a link when an image is included as media but this isn't a tidy solution when there is no valid link. Using the iif helped in these cases

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Ciaran Higgins ,

You are correct to use the iif in order to return a string. The pop-up will interpret it as simple text or when it is a valid URL it will present the link with a text like "more information" that is clickable. Is it possible to share a valid example of a URL that will be return?

0 Kudos
higgy7
by
New Contributor III

Hi Xander Bakker

You got me thinking the full name has spaces in it and that might be why this is not working, when the link is copied to an internet browser the spaces are automatically filled with %.

 

After figuring this out I tried the following:

 

var removespaces = Replace($feature.FULLNAME, ' ', '%')

var link = 'http://telemweb/graph/' + removespaces +'?Historic&applet'

 

IIf($feature["TELEMETRY_MATCH"]=='YES', link , 'Currently not linked to telemetry')

 

However it does not return the correct output, it now just says no information available, is this % a special character, if I use ? the popup displays, although not the correct url:

 

 

 

Example of full name :

NWA1A BTCC C Diamond.Coolagh Road LM.Points.Coolagh Bolie Flow

 

Example of full correct url:

 

http://telemweb/graph/NWA1A%20BTCC%20C%20Diamond.Bolie%20WPS.Points.Analogue%20Inputs.Pumped%20Flow?...

0 Kudos
higgy7
by
New Contributor III

**UPDATE**

Using %20 worked, the link says more info but i can live with that if this can't be changed.

var removespaces = Replace($feature.FULLNAME, ' ', '%20')

XanderBakker
Esri Esteemed Contributor

Hi Ciaran Higgins ,

I'm glad it works now. Just to be on the safe side, it would be better not to use Replace, but to use the UrlEncode Arcade function. This will make all characters valid for use in a URL.

To use your example text:

UrlEncode("NWA1A BTCC C Diamond.Coolagh Road LM.Points.Coolagh Bolie Flow")

Returns:

NWA1A%20BTCC%20C%20Diamond.Coolagh%20Road%20LM.Points.Coolagh%20Bolie%20Flow

So just use this:

var link = 'http://telemweb/graph/' + UrlEncode($feature.FULLNAME) +'?Historic&applet'
higgy7
by
New Contributor III

Hi Xander Bakker

I tried to use the UrlEncode but get Execution Error:Runtime Error: Function Not Found: UrlEncode.

Looking into the function it is only available from version 1.7 but i am trying to do this in our Portal which is 10.6.1 unfortunately  

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Ciaran Higgins ,

I see... You are using portal, right? What version of Enterprise do you have?

UrlEncode was introduced in Arcade version 1.7 which means that you need Enterprise / portal 10.7.1 to use it.

0 Kudos
higgy7
by
New Contributor III

Xander Bakker

Both enterprise and portal are 10.6.1

Thanks for all your help it has been very useful and informative!