Select to view content in your preferred language

Use Arcade to add href hyperlinks to unique list

3451
18
Jump to solution
01-10-2024 10:33 AM
Paco
by
Frequent Contributor

Hello community!   I have a Field of unique coded values.  these unique codes reference a full URL in a Table. however for each Feature there could be multiple codes(that are separated by piping '|').  example: WoodOthers1948 | Barnes1953 | HailOthers1971

in the past,  I have hard coded the URLs to the codes and used HTML 'href' in the Arcade window to get my results,  however,  there are hundreds of these combinations.

I would like to have the attribute codes show in the popup and each individual code would be hyperlinked/href to their unique URL.

*this is visually how it should look in the popup,  but each coded value would be a unique hyperlink-

Data Source: WoodOthers1948 | Barnes1953 | HailOthers1971 | StevenOthers1974 | Condon1992 | CarrollOthers1999 | KirkhamNavarre2003 | CarrollOthers2014

I have thought of using 'Decode' to reassign the codes to URLs,  but not sure how to read the clicked $feature list in to assign those individual URLs each time.

Any help?  im assuming creating a unique Array will help, but accessing and href'ing each code correctly back to the coded text list is still an issue.

thx!

0 Kudos
18 Replies
KenBuja
MVP Esteemed Contributor

OK, I see what's going on. I overlooked the fact that this is in an expression where you're already using backticks. Try this instead

push(output, '<a href="' + f.URL + '">${dsource}</a>');

 

0 Kudos
Paco
by
Frequent Contributor

Hm.  just returning a blank entry now.   and again the "$" before the 'dsource' is throwing a "Uncaught ReferenceError: dsource is not defined".   and if i remove that "$" it just returns blank with no error.

this syntax is getting frustrating..since I know your code has worked in the past 😞

0 Kudos
Paco
by
Frequent Contributor

UPDATE.   okay,  I am now returning the correct number of entries and the correct URLs.   but the return is returning as a string between the href single quotes..

Paco_0-1733260602100.png

I believe i was missing the "@" symbol for the Filter variable(@dsource)

gettin close!...

0 Kudos
KenBuja
MVP Esteemed Contributor

Urgh...I'm not concentrating hard enough today

push(output, '<a href="' + f.URL + '">' + dsource + '</a>');

 

0 Kudos
Paco
by
Frequent Contributor

Again,  sooooo close!   im still getting that full string between the single quotes?   ..but it is adding the 'dsource' correctly now  🙂    just need to get the string to be read as html and we'd be in business!   ..this is exciting(for me at least!).   this is where i wished those literal backticks would work..?

Paco_0-1733262023761.png

 

0 Kudos
KenBuja
MVP Esteemed Contributor

Usually links get sanitized with a simple return, which is why you have to use an Arcade element with popups for html elements.

0 Kudos
Paco
by
Frequent Contributor

Well not exactly sure what your response exactly means,  but in this Return the href links are active and exactly what I need,  but the type of text return format is not what im looking for.

is there a way to remove the default Table formatting and return a plain text datatype and keep the active links?

    return {
      output
    }
 
Paco_0-1733268026011.png

 

0 Kudos
KenBuja
MVP Esteemed Contributor

This isn't the most efficient code, so I can imagine it's slower with longer array lists. Since it has to make a query for each item in the list, multiple requests are sent back to the server. You might look at @jcarlson's blog about "memorizing" the table and see if that makes a measurable difference.

You could also just read the table into a dictionary and use the code field as a key to get the URL value instead of using the Filter on the Table.

0 Kudos
Paco
by
Frequent Contributor

Yep,  understood and agreed.  Code efficiency will need to be looked at.  However, your code definitely helped us get over that first hump,  and truly does not slow the popups down too much(2-3 seconds depending on the array list pulled, which can go up to about 10 Codes).   For now,  our task has been automated,  thanks again.   But yes,  we will look at the efficiency and update where needed..and your link to "Memorizing" is a terrific post, full of great ideas.

Thanks again!

p

0 Kudos