Select to view content in your preferred language

Use Arcade and HTML in popup with IF-statement to show or not show dynamic URL

767
5
Jump to solution
02-02-2025 02:21 PM
Labels (1)
SveinungBertnesRåheim
Frequent Contributor

I have a fairly simple issue. I have a public dataset for inspection of street lights. I have connected a survey123 schema to the feature set.

I want to show all street lights that are "OK" with a green symbol. I a malfunction is reported, the symbol changes to red.

I want the Popup to show a url to the survey123 when you click on a "green" symbol. If a malfunction is reported, you get a message stating something like "a malfunction is already reported". 

In a field list in the popup, I can get this fairly easy with an iif-arcade expression:

 Var SurveyURL = "https://survey123.arcgis.com/share/e59bac1c82004ee49bc1dbfb321a0fd0?mode=edit&globalId=" +$feature.GlobalID IIF($feature.Feilmelding=="OK", SurveyURL, "Det er alt meldt feil på dette lyset") 

 
This look like this in the field list:
SveinungBertnesRheim_0-1738534364261.png

I found this post, using arcade to show attachments when they exist, or another text when no attachments exist. 
https://community.esri.com/t5/arcgis-online-questions/arcade-expression-to-return-html-text/m-p/1315...

I get it to work on data where a malfunction report is already done, but I cant get it work to show the popup.

Here is my code: (the data is not shared with public, so it will not work.
Can anyone give a hint?

 

 

 

Var SurveyURL = "https://survey123.arcgis.com/share/e59bac1c82004ee49bc1dbfb321a0fd0?mode=edit&globalId=" + $feature.GlobalID
Var Feilmelding = $feature.Feilmelding=="OK"
Var Resultat = `<strong>"Det er allerede meldt feil på dette lyset"</strong>`

if (Feilmelding) {
return
  Resultat = `<p><strong><a href="${SurveyURL}">Meld inn feil på lyspunkt</strong></a></p>`
}


  return {
    type : 'text',
  text : Resultat
  }

 

 

 

 

 

 

 

0 Kudos
1 Solution

Accepted Solutions
SveinungBertnesRåheim
Frequent Contributor

Problem solved. I made an error, put in a "return" in line 6 that was not supposed to be there:
SveinungBertnesRheim_0-1738584096493.png

Var SurveyURL = "https://survey123.arcgis.com/share/e59bac1c82004ee49bc1dbfb321a0fd0?mode=edit&globalId=" + $feature.GlobalID
Var Feilmelding = $feature.Feilmelding=="OK"
Var Resultat = `<strong><font size = "3" color="Blue">Det er allerede meldt feil på dette lyset.</strong></font>`

if (Feilmelding) {
  Resultat = `<p><strong><font size = "5" color="Blue"><a href="${SurveyURL}">Meld inn feil på lyspunkt</strong></font></a></p>`
}

  return {
    type : 'text',
  text : Resultat
  }

 

This code works as expected. The answer was in this post, just needed to change the code correct from attachments to an attribute value.

View solution in original post

5 Replies
MErikReedAugusta
MVP Regular Contributor

As an aside, it might be helpful if your code blocks were all using the code block functions on the boards.  There's no option for "Arcade", but if you use "JavaScript", it'll mostly get the syntax highlighting correct.  That button looks like </>, though you might have to hit the ••• button first, to see it.

Also, I might be losing the context a bit due to the language barrier, so bear with me.  If you're able to share any larger contexts as an image or map link, it might help.

---

My first thought is that the other question you linked might actually be a more direct solution.  You were initially able to get the link to show up in the right circumstances, but the issue was largely one of formatting.  Maybe instead of an Arcade expression, you should be inputting an Arcade element, as discussed in the other post.  That would allow you to wrap your link in HTML formatting code to get the appearance you prefer.

Another option might be some clever/back-door use of filters & duplicate layers.  It doesn't look like you can directly add filters to the Pop-up, but you could sneakily duplicate the layer.  Copy A shows all symbols where the status is "OK", and has the pop-up configured for that situation.  Copy B shows all other symbols, and has the pop-up configured accordingly.  It'll be messy if anyone is looking at legends or content panes, but it'd likely work.

------------------------------
M Reed
"The pessimist may be right oftener than the optimist, but the optimist has more fun, and neither can stop the march of events anyhow." — Lazarus Long, in Time Enough for Love, by Robert A. Heinlein
SveinungBertnesRåheim
Frequent Contributor

I have tried to enter the code in a code block. I was only allowed to use one code block in a post.
Here are two pictures to explain my issue further.
Picture one shows the popup when an error is already reported. On top marked with red you can see the field list. This works, with its limitations. Below, marked with blue is the arcade-expression. This gives correct result for this situation. I get an explanation-text with my own html-formatting.

SveinungBertnesRheim_0-1738569076484.png

Here is the other situation, no malfunction-report have been sent. Then the field list-view with the iif-arcade-expression works as expected. But without the desired formatting. The arcade-expression does not return anything. This is what I am asking for. And I would appreciate not to make two duplicate layers etc.

SveinungBertnesRheim_1-1738569288170.png

 

 

0 Kudos
MErikReedAugusta
MVP Regular Contributor

The forums not allowing you to insert more than one code block is certainly odd; I haven't encountered that.  Though I know if you have a code block selected and you hit that button again, it'll generally edit the selected one, rather than inserting a new one.  That, or we could always blame the standard cosmic ray bitflip/a wizard did it.

Glad to hear that you solved the original problem in the thread!  It really does seem always the simplest "D'oh" moments that trip us up, isn't it?  I've been there many times.

------------------------------
M Reed
"The pessimist may be right oftener than the optimist, but the optimist has more fun, and neither can stop the march of events anyhow." — Lazarus Long, in Time Enough for Love, by Robert A. Heinlein
0 Kudos
SveinungBertnesRåheim
Frequent Contributor

Problem solved. I made an error, put in a "return" in line 6 that was not supposed to be there:
SveinungBertnesRheim_0-1738584096493.png

Var SurveyURL = "https://survey123.arcgis.com/share/e59bac1c82004ee49bc1dbfb321a0fd0?mode=edit&globalId=" + $feature.GlobalID
Var Feilmelding = $feature.Feilmelding=="OK"
Var Resultat = `<strong><font size = "3" color="Blue">Det er allerede meldt feil på dette lyset.</strong></font>`

if (Feilmelding) {
  Resultat = `<p><strong><font size = "5" color="Blue"><a href="${SurveyURL}">Meld inn feil på lyspunkt</strong></font></a></p>`
}

  return {
    type : 'text',
  text : Resultat
  }

 

This code works as expected. The answer was in this post, just needed to change the code correct from attachments to an attribute value.

BertKraan
Occasional Contributor

thanks for sharing!

 

0 Kudos