Hello,
I have an Arcade script that inserts the name of a boundary polygon if it intersects with the feature. How do I show a comma between only the ones where it intersects multiple polygons? My current code just adds a "," to everyone regardless if it's only one value.
var land = FeatureSetByName($datastore,"Boundary_Aug2024",["Name"], true)
var intersectLayer = Intersects(land, Geometry($feature))
var result = '';
if (Count(intersectLayer) > 0) {
for (var layer in intersectLayer) {
result += layer.Name+(", ") ;
}
} else {
result = "Null"
}
return result
Solved! Go to Solution.
You can add the items to an array and use the Concatenate function. This wouldn't add an extra comma if there is only one result.
var land = FeatureSetByName($datastore, "Boundary_Aug2024", ["Name"], true);
var intersectLayer = Intersects(land, Geometry($feature));
var result = [];
if (Count(intersectLayer) == 0) return "Null";
for (var layer in intersectLayer) {
Push(result, layer.Name);
}
return Concatenate(result, ", ");
Looks like you can nest if/else statements if you scroll down in the linked documentation to the section titled "Nested if/else". Another option it shows there is the IIF statement that might work for you as well
So I would create an nested if statement where if it's greater than one, then it inserts a comma between the values? How do I specify between them and not end up with another , after the end?
You can add the items to an array and use the Concatenate function. This wouldn't add an extra comma if there is only one result.
var land = FeatureSetByName($datastore, "Boundary_Aug2024", ["Name"], true);
var intersectLayer = Intersects(land, Geometry($feature));
var result = [];
if (Count(intersectLayer) == 0) return "Null";
for (var layer in intersectLayer) {
Push(result, layer.Name);
}
return Concatenate(result, ", ");
of course this is the best answer! Thanks for showing this approach @KenBuja
Amazing! Thank you so much @KenBuja