I've written an Arcade expression for a layer's popup in the new map viewer, based on records from a related table. The expression returns the expected text, but the layer's popup is empty.
Adding a new Arcade expression with the default code works:
var dossiers = FeatureSetById($datastore, "4")
// Filter related features by using a common attribute
var CD = $feature.Code
var filterStatement = "domeinnummer = @CD"
// Related features as a variable
var relatedData = Filter(dossiers, filterStatement)
// Sort related features by oldest to newest
var relatedDataSorted = OrderBy(relatedData, 'Dossiernummer ASC')
// Build the pop-up string by iterating through all related features
var popupString = "Domein " + $feature.Domein
for (var f in relatedDataSorted){
popupString += TextFormatting.NewLine + DefaultValue(Text(f.Dossiernummer), 'geen nr') + " - " + DefaultValue(f.Naam_OVAM_Dossier, 'geen naam')
+ TextFormatting.NewLine + " " + DefaultValue(f.Expert_Status, 'geen status')
}
DefaultValue(popupString, 'Geen dossier')
Solved! Go to Solution.
It helps tremendously, because now I can see what you're doing wrong.
Based on the working default code, you're trying to add an Arcade element. For that to work, you need to return a dictionary (documentation). In your actual expression, you're not doing that, instead you return a string.
There is a difference between a "normal" Arcade expression (#1 in the images) and an Arcade element (#2). The value of a "normal" Arcade expression can be shown in the fields list. The Arcade element is more customizable, and, as said, you need to return a dictionary.
Replace your last line with this:
return {
type: 'text',
text: DefaultValue(popupString, 'Geen dossier')
}
It would help if post your actual code...
Hi Johannes, I've added it to the question, but since it works, I don't see how seeing the code would help.
Based on this example
It helps tremendously, because now I can see what you're doing wrong.
Based on the working default code, you're trying to add an Arcade element. For that to work, you need to return a dictionary (documentation). In your actual expression, you're not doing that, instead you return a string.
There is a difference between a "normal" Arcade expression (#1 in the images) and an Arcade element (#2). The value of a "normal" Arcade expression can be shown in the fields list. The Arcade element is more customizable, and, as said, you need to return a dictionary.
Replace your last line with this:
return {
type: 'text',
text: DefaultValue(popupString, 'Geen dossier')
}
Thanks for pointing me to the right direction Johannes. I tried my code in an expression and as an element, for some reason it was not working in an expression, now it does. And your code works with the element.
Have a great day too 🙂