Hi everyone,
I am very new to Arcade and am trying to create an expression that can generate a list of needed maintenance activities in the pop-up of an associated feature. This particular dataset involves a maintenance record for trees, where users can add necessary maintenance types to a related table for each marked tree. When the maintenance activity is completed, the user updates this related record by adding the date in which the maintenance was completed and switching the attribute for the 'Maintenance Needed' field from true to false.
I would like to build an expression that can filter through these related records, choosing only the ones where 'Maintenance Needed' = True, and listing out each 'Maintenance Type' that has been assigned to the tree. That way, my users can just click on the pop-up and view what maintenance still needs to be completed on said tree.
Any help would be appreciated, thank you!
Solved! Go to Solution.
I was able to figure it out! I don't know how to remove the comma from the last maintenance activity needed, but at least the activities are displaying in the pop-up!
Below is my code in case anyone else would like to reference it.
Do you have a relationship set up between the FeatureSet and the related table? If so, you can use this syntax to get the related records
var related = FeatureSetByRelationshipName($feature, "the relationship name");
If not, then you'll get the related records by filtering the table using the common field (relateField, in this example).
var relTable = FeatureSetByName($map,'table', ['*'], false);
var attribute = $feature.relateField;
var related = Filter(relTable, "relaterField = @attribute");
From that, filter the related records for the ones that need maintenance.
var records = Filter(related, "MaintenanceNeeded = 'True'");
if (Count(records) = 0) return "No maintenance needed";
var output = "Maintenance Needed: " + TextFormatting.NewLine;
for (var f in records) {
output += " " + f.MainenanceType + TextFormatting.NewLine;
}
return output;
One way to remove that last comma:
return Left(output, Count(output)-2)
R_
You can Push the results into an array and use Concatenate to put them into a comma-separated string
if (Count(records) == 0) return "No maintenance needed";
var output = [];
for (var f in truerecords) {
Push(output, f.Main_Type)
}
return Concatenate(output, ', ')
Quick question since this post is fairly new. Is FeatureSetByRelationshipName asking for the name of the related table, or the actual name of the relationship as it was set in ArcGIS Pro? I think I'm running into an issue with just that first line.
It uses the relationship name that's set up in ArcGIS Pro