Select to view content in your preferred language

ArcGIS Online Webmap Pop-up - Attribute Expression Code not working

146
1
Jump to solution
yesterday
MelissaMitchell
Occasional Contributor

Hello,

I've created an attribute expression that looks at a field to see if there is a url. If there is no url, do not show "Click Here". If there is a url, show Click Here to view project details. 

I can get the field to show the url if I take out the html code. Once I add the html code I don't see anything.

var link = $feature.Project_Li;
if (IsEmpty(link)){
  return null;
}else {
  return '<a href="' + link + '">Click Here</a>';
}
 
I also tried this code, so if link (attribute) is null you wouldn't see "Click Here". And in the HTML in the popup I did the <a href="Project_Li">AttributeExpression</a>. Click here still shows up even if it's null.
 
var link = $feature.Project_Li;
if (IsEmpty(link)){
  return " ";
}

return "Click Here";
 
Thank you in advance for the help!
0 Kudos
1 Solution

Accepted Solutions
MelissaMitchell
Occasional Contributor

I figured it out!!!! I had to clean the attribute. I covered all the nulls.

var link = $feature.Project_Li;
var cleanURL = Trim(Text(link));
if (
  IsEmpty(link) ||
  CleanURL == "" ||
  Lower(CleanURL) == "null" ||
  Lower(CleanURL) == "<null>" ||
  Lower(CleanURL) == "none"
) {
  return "";
}
return "Click Here";

 

View solution in original post

1 Reply
MelissaMitchell
Occasional Contributor

I figured it out!!!! I had to clean the attribute. I covered all the nulls.

var link = $feature.Project_Li;
var cleanURL = Trim(Text(link));
if (
  IsEmpty(link) ||
  CleanURL == "" ||
  Lower(CleanURL) == "null" ||
  Lower(CleanURL) == "<null>" ||
  Lower(CleanURL) == "none"
) {
  return "";
}
return "Click Here";