Add Related table attributes onto polygon's pop-up

1184
8
Jump to solution
03-31-2023 09:13 PM
Labels (3)
LearnThenShare
New Contributor III

Hello!  I need assistance with adding related table fields to a polygons popup.  The source data is below.

Thank you!  @JohanLei1  

polygon: https://maps2.dcgis.dc.gov/dcgis/rest/services/DCGIS_DATA/Property_and_Land_WebMercator/MapServer/40

related table: https://maps2.dcgis.dc.gov/dcgis/rest/services/DCGIS_DATA/Property_and_Land_WebMercator/MapServer/69 

0 Kudos
3 Solutions

Accepted Solutions
KenBuja
MVP Esteemed Contributor

This expression will show each of the surveys' url

var related = FeatureSetByRelationshipName($feature, "DCGIS.SURDOCS");
var output = `${count(related)} survey`;
if (count(related) != 1) output += "s";
for (var rec in related) {
  output += `${TextFormatting.NewLine}• ${rec.FILENETLINK}`
}
return output;

. However, I don't think there's currently a way to make each of them clickable

popup2.png

View solution in original post

KenBuja
MVP Esteemed Contributor

All the attributes from each related record are available to the popup, as shown in this script.

 

var counter = 1;
var related = FeatureSetByRelationshipName($feature, "DCGIS.SURDOCS");
var relatedCount = count(related);
var output;

for (var rec in related) {
  output += `Record ${counter++}`
  for (var attribute in rec){
    output += `${TextFormatting.NewLine}•  ${attribute}: ${rec[attribute]}`   
  }
  if (counter <= relatedCount) output += `${TextFormatting.NewLine}${TextFormatting.NewLine}`
}
return output;

 

 

View solution in original post

KenBuja
MVP Esteemed Contributor

With some more work, I was able to get a clickable link for each related survey. This is using the popup content element. Add in an Arcade element and use this script

var related = FeatureSetByRelationshipName($feature, "DCGIS.SURDOCS");
var relatedCount = count(related);
var output;

if (relatedCount == 0) {
  output = `<p>There are no surveys for this property.<\p>`;
} else if (relatedCount == 1) {
  var rec = First(related);
  output = `There is 1 survey for this property:
    <br>&nbsp •  <a href="${rec.FILENETLINK}">${rec.DOCGUID}</a>`;
} else {
  output = `There are ${relatedCount} surveys for this property:`;
  for (var rec in related) {
    output += `<br>&nbsp •  <a href="${rec.FILENETLINK}">${rec.DOCGUID}</a>`;
  }
}

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

survey1.png

View solution in original post

8 Replies
KenBuja
MVP Esteemed Contributor

This expression will show how many surveys from the table have been done at a property.

var related = FeatureSetByRelationshipName($feature, "DCGIS.SURDOCS");
var output = `${count(related)} survey`;
if (count(related) != 1) output += "s";
return output;

You can use that expression in the popup like this

related.png

LearnThenShare
New Contributor III

Hi @KenBuja , Thank you for the expression.  If I am looking to add the one or more attributes from the related table, not simply a count, is there an additional Arcade expression that makes that happen?  The related table has an image type field and an image URL.  I would like the image type attribute(s) and the image URL(s) to show in the popup - not only accessible in the "related tables" link at the bottom.  Thank you!

0 Kudos
KenBuja
MVP Esteemed Contributor

This expression will show each of the surveys' url

var related = FeatureSetByRelationshipName($feature, "DCGIS.SURDOCS");
var output = `${count(related)} survey`;
if (count(related) != 1) output += "s";
for (var rec in related) {
  output += `${TextFormatting.NewLine}• ${rec.FILENETLINK}`
}
return output;

. However, I don't think there's currently a way to make each of them clickable

popup2.png

LearnThenShare
New Contributor III

Hi @KenBuja : Thank you again for the additional expression!  This is very promising.  I do wonder what are the technical limitations specific to bringing in the full data from related tables.  I will implement the expression that you provided and let you know when it works (and accept as solution), and I will let you know if I find out how to make all the link data actual links to the image.  Thank you!!!

0 Kudos
KenBuja
MVP Esteemed Contributor

All the attributes from each related record are available to the popup, as shown in this script.

 

var counter = 1;
var related = FeatureSetByRelationshipName($feature, "DCGIS.SURDOCS");
var relatedCount = count(related);
var output;

for (var rec in related) {
  output += `Record ${counter++}`
  for (var attribute in rec){
    output += `${TextFormatting.NewLine}•  ${attribute}: ${rec[attribute]}`   
  }
  if (counter <= relatedCount) output += `${TextFormatting.NewLine}${TextFormatting.NewLine}`
}
return output;

 

 

KenBuja
MVP Esteemed Contributor

With some more work, I was able to get a clickable link for each related survey. This is using the popup content element. Add in an Arcade element and use this script

var related = FeatureSetByRelationshipName($feature, "DCGIS.SURDOCS");
var relatedCount = count(related);
var output;

if (relatedCount == 0) {
  output = `<p>There are no surveys for this property.<\p>`;
} else if (relatedCount == 1) {
  var rec = First(related);
  output = `There is 1 survey for this property:
    <br>&nbsp •  <a href="${rec.FILENETLINK}">${rec.DOCGUID}</a>`;
} else {
  output = `There are ${relatedCount} surveys for this property:`;
  for (var rec in related) {
    output += `<br>&nbsp •  <a href="${rec.FILENETLINK}">${rec.DOCGUID}</a>`;
  }
}

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

survey1.png

LearnThenShare
New Contributor III

Hi @KenBuja 

Can you assist again with a similar expression?  FYI I am still on Classic Map if that matters here.

The polygon: https://maps2.dcgis.dc.gov/dcgis/rest/services/DCGIS_DATA/Property_and_Land_WebMercator/MapServer/40

The related table: https://maps2.dcgis.dc.gov/dcgis/rest/services/DCGIS_DATA/Property_and_Land_WebMercator/MapServer/53

The fields from the related table for the popup: 

  • BIDNAME ( type: esriFieldTypeString, alias: BIDNAME, length: 50 )
  • BIDTOTALDUE ( type: esriFieldTypeDouble, alias: BIDTOTALDUE )
  • BIDCOLLECTED ( type: esriFieldTypeDouble, alias: BIDCOLLECTED )
  • BIDBALANCE ( type: esriFieldTypeDouble, alias: BIDBALANCE )

Thank you!

0 Kudos
KenBuja
MVP Esteemed Contributor

Give this a try:

var rec = First(FeatureSetByRelationshipName($feature, "DCGIS.ITSPE", ['BIDNAME', 'BIDTOTALDUE', 'BIDCOLLECTED', 'BIDBALANCE']));

return `${rec.BIDNAME}
    • Total Due: ${Text(rec.BIDTOTALDUE, '$#,###.00')}
    • Collected: ${Text(rec.BIDCOLLECTED, '$#,###.00')}
    • Balance: ${Text(rec.BIDBALANCE, '$#,###.00')}`
0 Kudos