Disclaimer: I'm fairly new to Arcade.
Data: I have three data layers in an AGO web map - a polygon layer of municipalities, and two related tables. There's two fields in the municipality table indicating whether or not that municipality is a certain type of client (EngineeringClient and PlanningClient.) There is a corresponding related table for each client type with binary (Y/N) fields for each type of service that could potentially be offered.
I currently have the popup configured to read each of those two fields in the polygon layer and return a statement that the community is a client if either returns true.
Problem: I want my code to identify municipalities for which a client type is true, then iterate through all of the service fields and return the field name for all that have a Y for that record. I have defined a FeatureSet for each related table to narrow the fields down to just the services.
What I would like to do:
Code:
// define engineering and planning clients
var Eclient = $feature.ENGINEERING;
var Pclient = $feature.PLANNING;
//define a variable
var name = $feature.NAME
// define a table of engineering services
var Eserv = (FeatureSetByRelationshipName($feature,"Engineering_2020", ["PLANREVIEW", "WATER", "SANITARY", "STORM", "ROAD", "WATERTREATMENT", "GIS", "ASNEEDED"], false);
// define a table of planning services
var Pserv = FeatureSetByRelationshipName($feature,"Planning_2020", ["CodeBook", "DevelopmentGuidebook", "PublicFacilitation", "MasterPlan", "RecPlan_Grants_Other", "DistrictStudies_Plans", "TIFPlan", "RetainerService", "HourlyServices", "Website", "ZoningAmendments", "StreetScapeDesign", "Wayfinding", "FormBasedCodes"], false);
// iterate through engineering services and print result
if (Eclient == "Y"){
for (var i in eServ){
if (i.PLANREVIEW == "Y"){
return 'Plan Review'
} else {
return ""
}
if (i.Field_Name == "Y") {
return "Field Name"
} else {
return ""
}
}
};
With the code repeating IF statements for all service fields. Then it would run through all of the Planning services as well once we get the syntax right on the first part.
The problem is that multiple IF statements require using a CONTINUE statement, which breaks the function when I specify a RETURN.
So the workaround I'm currently using requires multiple expressions.
What I'm actually doing:
Code in use:
// define variable
var name = $feature.NAME
//filter to record
var eService = Filter(FeatureSetByName($datastore,"Engineering_2020"),"NAME LIKE '%"+name+"%'")
// iterate through engineering services and print result
for (var i in eService){
if (i.PLANREVIEW == "Y"){
return TextFormatting.NewLine + 'Plan Review'
}
}
This is then repeated as a separate expression for each service type, and concatenated through the custom attribute display.
Engineering Services:{expression/expr1}{expression/expr2}{expression/expr3}{expression/expr4}{expression/expr5}{expression/expr6}{expression/expr7}{expression/expr8}
Planning Services: {expression/expr10}{expression/expr11}{expression/expr12}{expression/expr13}{expression/expr14}{expression/expr15}{expression/expr16}{expression/expr17}{expression/expr18}{expression/expr19}{expression/expr20}{expression/expr21}{expression/expr22}{expression/expr23}{expression/expr24}
Does anyone know how to write this more efficiently?
TIA
--Ariana