After scouring the forums and anything else (since I am just learning this), I have gotten to this place with the below code. I need to return the attribute called "filepath" of the 2nd related record, 3rd related record, etc. I have to do a separate expression for each one, so I can display it is as a URL and Photo in the pop up. I got the first record to work in another expression, but I'm clearly not doing something right here, since this doesn't return anything when I try to get the 2nd or 3rd value.
--------------------------------------------------------------------------------------------------
var index = 0;
var related_table = OrderBy(FeatureSetByRelationshipName($feature,"%vw_EventAttachments"), "AttachmentID");
var filter_query = "EGUID = '" + $feature["EGUID"] + "'";
var related_data_filtered = Filter(related_table, filter_query);
var related_data_filtered_count = Count(related_data_filtered);
var output = "";
for (var row in related_data_filtered) {
if (related_data_filtered_count > 0)
{
index++;
if (index == 2)
return (related_data_filtered).Filepath;
}
else { output = " ";}
return output;
}
Solved! Go to Solution.
You are on the right track, your for loop is just a little wonky.
What you're doing is this:
So the code gets to the first row, sees that index = 1 != 2 and returns " ".
Copy this function and change the return_index for each instance.
// the number of the row from which you want to return the AttachmentID
// 1 for first, 2 for second, ...
var return_index = 2;
var related_table = OrderBy(FeatureSetByRelationshipName($feature,"%vw_EventAttachments"), "AttachmentID");
var filter_query = "EGUID = '" + $feature["EGUID"] + "'";
var related_data_filtered = Filter(related_table, filter_query);
var related_data_filtered_count = Count(related_data_filtered);
// return early if you want to get an attachment that doesn't exist
if(return_index > related_data_filtered_count) {
return "";
}
var index = 1;
for (var row in related_data_filtered) {
if(index == return_index) {
return row.Filepath;
}
index++;
}
You are on the right track, your for loop is just a little wonky.
What you're doing is this:
So the code gets to the first row, sees that index = 1 != 2 and returns " ".
Copy this function and change the return_index for each instance.
// the number of the row from which you want to return the AttachmentID
// 1 for first, 2 for second, ...
var return_index = 2;
var related_table = OrderBy(FeatureSetByRelationshipName($feature,"%vw_EventAttachments"), "AttachmentID");
var filter_query = "EGUID = '" + $feature["EGUID"] + "'";
var related_data_filtered = Filter(related_table, filter_query);
var related_data_filtered_count = Count(related_data_filtered);
// return early if you want to get an attachment that doesn't exist
if(return_index > related_data_filtered_count) {
return "";
}
var index = 1;
for (var row in related_data_filtered) {
if(index == return_index) {
return row.Filepath;
}
index++;
}
Thank you soooo much! It works great.