Select to view content in your preferred language

Arcade expression correct but doesn't show up in popup

1677
4
Jump to solution
12-12-2022 03:02 AM
Geraldine
Regular Contributor

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:

return {
  type : 'text',
  text : 'place your text or html here' //this property supports html tags
}
 
The layer and the related table both have popups enabled and all fields are visible. So what am I doing wrong?
 
This is the code:

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

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

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.

 

JohannesLindner_1-1670850745743.png

JohannesLindner_2-1670850803088.png

 

 

Replace your last line with this:

 

return {
    type: 'text',
    text: DefaultValue(popupString, 'Geen dossier')
}

 

 


Have a great day!
Johannes

View solution in original post

4 Replies
JohannesLindner
MVP Frequent Contributor

It would help if post your actual code...

JohannesLindner_0-1670847280076.png

 

JohannesLindner_1-1670847292079.png

 


Have a great day!
Johannes
0 Kudos
Geraldine
Regular Contributor

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

0 Kudos
JohannesLindner
MVP Frequent Contributor

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.

 

JohannesLindner_1-1670850745743.png

JohannesLindner_2-1670850803088.png

 

 

Replace your last line with this:

 

return {
    type: 'text',
    text: DefaultValue(popupString, 'Geen dossier')
}

 

 


Have a great day!
Johannes
Geraldine
Regular Contributor

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 🙂

0 Kudos