Displaying all information from a FeatureSetByRelationshipName table in Pop-Up Window

188
1
06-02-2020 12:06 AM
BarrettLewis
New Contributor II

Hello, I am a total newbie with Arcade and coding in general, so please bear with me. I am trying to get all display all the information from a FeatureSetByRelationshipName function results. I am trying to follow the following link:

How to get attribute with last date modified from related table using Arcade 

Based on the input from that post, I am able to display one record at a time, because the advice only tells me how to derive results using the "First" function. I attempted to use a For loop, but I'm basically still at the same point. I can only get result at a time. This is my code: 

var relatedrecords = FeatureSetByRelationshipName($feature,"PDX_Metro_Placement_Reporting_No_TicketHome", ["Reporting_Program_Recode"]);
var cnt = Count(relatedrecords);

var relatedinfo = "";
if (cnt > 0) {
for (var record in relatedrecords) {
relatedinfo = record.Reporting_Program_Recode + TextFormatting.NewLine;
}
}

return relatedinfo;

However, if you see the attached image, there is often more than one result for this field. What I want in my pop-up column is each unique value listed once, preferably in alphabetical order. So per the attached image, when you click on the point data for this client, it would say "SSVF - RRH", then a line break, and then "Vets - PSH". Right now I only get SSVF - RRH using the above for loop or using the first function. Can someone please help me out?

0 Kudos
1 Reply
XanderBakker
Esri Esteemed Contributor

Hi Barrett Lewis ,

In your code, the reason that you get a single value, is because you are using "=" and not "+=" on line 7. That is why during the loop the value is not added to the result, but it replaces the previous value. 

I think in this case you should be able to use the GroupBy function on the related records to get a unique list of values Let me give you an example:

var relatedrecords = FeatureSetByRelationshipName($feature,"PDX_Metro_Placement_Reporting_No_TicketHome", ["Reporting_Program_Recode"]);
var cnt = Count(relatedrecords);

var relatedinfo = "";
if (cnt > 0) {
// use GroupBy to summarize the field Reporting_Program_Recode
var stats = GroupBy(relatedrecords, "Reporting_Program_Recode",
[{name:"count", expression:"Reporting_Program_Recode", statistic:"COUNT"}]);

// report the result
relatedinfo = "Reporting Program Recode:"
for (var stat in stats) {
relatedinfo += TextFormatting.NewLine + " - " + stat.Reporting_Program_Recode + " (" + stat.count + ")";
}

} else {
relatedinfo = "No related information";
}

return relatedinfo;