Create multiple hyperlinks from a field of a comma separated string

965
1
09-21-2021 12:00 PM
Labels (1)
RyanMiller6
New Contributor II

I have a feature layer on ArcGIS Online that contains a field of document names separated by commas (i.e. Easement1, Easement2, Easement3, etc.).  In the web map viewer pop-up, I would like to list each document name and hyperlink each to its respective document stored on sharepoint.  The pop-up element would look like something like below where W-0804 and W-0808 would each have a separate hyperlink to a document on a sharepoint site. 

RyanMiller6_0-1632250359018.png

The link would looking something like this: https://testsite.sharepoint.com/sites/ROW/Easements/{Agreements}.pdf

This kicker is that I would need the W-0804 and W-0808 in the hyperlink in place of {Agreements}.  

Thank you in advance!

 

   

0 Kudos
1 Reply
JohannesLindner
MVP Frequent Contributor

It is possible, but a bit cumbersome. The popup doesn't evaluate HTML code returned by an expression, so you will have to create multiple expressions like this:

// index of the agreement link you want to return
// 0 for first, 1 for second, ...
var return_index = 0
// split the agreements field
var agreements = Split($feature.Agreements, ", ")
// return early if you try to return an agreement that doesn't exist
if(return_index + 1 > Count(agreements)) {
  return ""
}
// return the specified agreement link
return "https://testsite.sharepoint.com/sites/ROW/Easements/" + agreements[return_index] + ".pdf"

 

Copy that expression multiple times (if your maximum agreement number is 5, you should have 5 expressions) and change the return_index. You shoulb be able to show the links in the popup's attribute table.

 

If you want to get fancy, you can create expressions for the agreement names, too:

// index of the agreement name you want to return
// 0 for first, 1 for second, ...
var return_index = 0
// split the agreements field
var agreements = Split($feature.Agreements, ", ")
// return early if you try to return an agreement that doesn't exist
if(return_index + 1 > Count(agreements)) {
  return ""
}
// return the specified agreement link
var sep = IIF(return_index == 0, "", ", ")
return sep + agreements[return_index]

 

Then you can create your example from above in the popup's HTML code:

Agreements: <a href="{expression/link1}">{expression/name1}</a><a href="{expression/link2}">{expression/name2}</a><a href="{expression/link3}">{expression/name3}</a><a href="{expression/link4}">{expression/name4}</a>

 


Have a great day!
Johannes