Arcade expression for pop-up

552
7
Jump to solution
03-08-2024 01:02 PM
Labels (2)
KarynaB
New Contributor II

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!

0 Kudos
1 Solution

Accepted Solutions
KarynaB
New Contributor II

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. 

View solution in original post

0 Kudos
7 Replies
KenBuja
MVP Esteemed Contributor

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;

 

KarynaB
New Contributor II

That almost worked! The expression is just not returning any of the field values under Maintenance Type. I've attached a screenshot for reference.

0 Kudos
KarynaB
New Contributor II

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. 

0 Kudos
RhettZufelt
MVP Frequent Contributor

One way to remove that last comma:

return Left(output, Count(output)-2)

R_

0 Kudos
KenBuja
MVP Esteemed Contributor

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, ', ')

 

Tiff
by
Occasional Contributor III

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.

0 Kudos
KenBuja
MVP Esteemed Contributor

It uses the relationship name that's set up in ArcGIS Pro

0 Kudos