Select to view content in your preferred language

Arcade Expression Not Returning Anything in Pop-up in Some Scenarios.

123
2
Jump to solution
Monday
MollyMoore
Frequent Contributor

I am using an Arcade expression with HTML to format a feature layer pop-up in a web map. The format looks great, but for several features, the pop-up is just blank - without even the heading attributes that are populated for all features. In some cases, the features do not have related records and/or images - I thought I accounted for that with if statements. I think this issue seems to be occurring when there are no related site account records. Can anyone see anything wrong with the code that would be making this occur?

// first get heading with attributes from selected feature
var output = "<p line-height: 1.6;><span style='font-size:2em;'><strong>"+$feature.site_name+" NHA</strong></span><br>"
output += "<span style='font-size:1.5em;'>A site of "+$feature.sig_rank+" significance.</span></p>"

// this is pulling in the attachment and displaying
var attach = Attachments($feature)
if(Count(attach) != 0) {
  var Part1 = "https://services2.arcgis.com/REST SERVICE URL"
  var ObjectID = $feature.OBJECTID
  var Part2 = "/attachments/"
  var AttachID = First(attach).ID
  var img_path = Part1 + ObjectID + Part2 + AttachID
  var img_caption = $feature.photo_caption
  output += "<p><img src="+img_path+"><br>"+img_caption+"</p>"
}

// get site description and tr summary
var related_site = FeatureSetByRelationshipName($feature, "Site_Accounts", ["site_desc","tr_summary"]);

if (!IsEmpty(related_site)) {
    var firstRel = First(related_site);
    var desc = firstRel["site_desc"];
    output += "<p><span style='font-size:1em;'>"+desc+"</span></p>"
    var tr_summ = firstRel["tr_summary"]
    if(!IsEmpty(tr_summ)) {
      output += "<p><span style='font-size:1.2em;'><strong>Threats and Recommendations</strong></span><br>"
      output += "<span style='font-size:1em;'>"+tr_summ+"</span></p>"
    }
}

// Get the related features
var relatedRecords = FeatureSetByRelationshipName($feature, "Threats_and_Recommendation_Bullets", ["threat_text"]);

// Check if any related records exist
if (Count(relatedRecords) > 0) {
  // Start an HTML unordered list
  output += "<span style='font-size:1.0em;'>Specific threats and stresses to the elements present at this site, as well as conservation actions, include:</span><br><ul>";

  // Loop through each related record
  for (var record in relatedRecords) {
    // Add a list item with the attributes you want to display
    output += "<li>" + record.threat_text + "</li>";
  }
  output+= "</ul>"
}

return {
	type : 'text', 
	text : output //this property supports html tags 
};
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

Lines 20 tests whether a relationship exists, not whether there are records in the relationship. The code fails when you try to access a field from a null in line 22

You'll have to test whether that relationship has any records.

if (Count(related_site) > 0) {

 

View solution in original post

2 Replies
KenBuja
MVP Esteemed Contributor

Lines 20 tests whether a relationship exists, not whether there are records in the relationship. The code fails when you try to access a field from a null in line 22

You'll have to test whether that relationship has any records.

if (Count(related_site) > 0) {

 

MollyMoore
Frequent Contributor

Thank you, this fixed the issue! Thanks for catching the problem and for the solution! 

0 Kudos