Hello! I'm trying to use Arcade to display text on a pop-up in Map Viewer. When I test the code within the new Arcade Editor, it works exactly as intended:
var lines = FeatureSetById($map, /* Sewer Line */ "184e8d5e05b-layer-7");
var bufferArea = Buffer($feature, 10, 'feet');
var intersectedLine = First(Intersects(lines, bufferArea));
var facilityId = '';
if(intersectedLine != null){
facilityId = intersectedLine.FACILITYID;
}
var cctvYears = FeatureSetById($map, /* SsTelevisedMains */ "184e8d5e05b-layer-8", ['LINETOPOINT', 'INSPECTION_DATE']);
var filteredYears = Filter(cctvYears, "SEGMENT_ID = '" + facilityId + "'");
var sortedYears = OrderBy(filteredYears, 'INSPECTION_DATE desc');
var lastYear = First(sortedYears);
var defects = FeatureSetByName($map, "SsCCTVConditions");
var LineToPoint = lastYear.LINETOPOINT;
var filteredDefects = Filter(defects, "LINETOPOINT = '" + LineToPoint + "'");
var topDefect = Filter(filteredDefects, "Grade >= 3");
var allDefects = '';
for(var d in topDefect){
allDefects = allDefects + "(" + d.Grade + ")" + " Type: " + d.PACP_CODE + " Distance: " + Round(d.DISTANCE, 2) + "\n";
}
return {
type : 'text',
text : allDefects //this property supports html tags
}
However, nothing shows up in the pop-up:
Based on my configuration, I assume the expression should be displayed above the Fields List and below the Title. Am I implementing the expression in the pop-up incorrectly? I can confirm that the same expression works in Field Maps and the newly implemented Forms in Map Viewer.
I'm not terribly familiar with arcade as well, but I wonder if you are returning a feature set or an feature? I've had similar troubles.
I ask because maybe you need to add the code into "Attribute Expressions" first vs "Arcade" in the pop up and then using the Text type in the pop up, add your expression there {expression/expr0} etc. It shouldn't matter whether it's before or after your fields.
But I could be totally wrong!
In the Fields List, Select Fields and put check box next to the expression to select it. Then you can move it wherever you want in the popup field list.
R_
Hi Rhett,
Thanks for the response! I tried that, however, the expression isn't showing up in the field list:
It appears as if you used the + Add content button in the main Pop-ups editor to add the </> Arcade Expression.
Not even sure why this is here as it seem to have no effect (as you are seeing).
If you go to the "Attribute expressions" option and add the expression there, it will then show up in the Select Fields list and will allow you to add it to the popup.
There is also an option at the bottom of the Select fields window to + Add expression. either method seems to work.
R_
I use the Arcade option when creating a custom chart! You'll notice with the "+Add Content Arcade" version, there are custom chart templates available which is not available in Attribute Expressions. Attribute Expression is just useful when just trying to create an additional custom, on the fly, attribute, as a individual "feature". Where the +Add Content Arcade way, creates "features sets"... which is needed for custom graphs. Can't create a "Feature set" in Attribute Expressions.
Hi Teresa,
This is what I'm looking to do - in the Arcade editor, I see there's templates for Field Lists, Charts and Rich text - I'm hoping to load the resulting string from my expression into rich text and display outside of the field list, for clarity of viewers.
Ohhh, gotcha! Well, I haven't tried rich text! But this Esri blog seems to put the var inside of ${variable name} whereas it looks like you've just put allDefects. Does return ${allDefects} make a difference?
Part 1: Introducing Arcade Pop-up Content Elements (esri.com)
I also noticed they put the entire return text inside ` ` accents