Select to view content in your preferred language

Possible bug? Arcade won't work for pop-up unless fields list component is added.

650
2
Jump to solution
09-09-2023 11:23 PM
hoshijun
Emerging Contributor

I used the following Arcade code from this forum to filter out empty fields. When I run it in the Arcade console, it seems to work fine. And it worked fine when I had the "Fields list" component added to the pop-up. However, when I only have the Arcade component selected, it will not display a filtered table. 

Is this a bug or is this intentional? Having two field tables would be redundant.

var flds = ['Field_1','Field_2','Field_3','Field_4','Field_5'];
var info = [];
var atts = {};

for (var i in flds) {
    var fldname = flds[i];
    if (!IsEmpty($feature[fldname])) {
        Push (info, {'fieldName': fldname}) 
        atts[fldname] = $feature[fldname];
    }
}

return {
    type: 'fields',
    title: 'My Title', 
    description : 'My description',
    fieldInfos:  info,
    attributes : atts 
}

 

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

This is intentional behavior.

For performance reasons, Arcade only loads the fields that are needed in the expression. It does that by checking the expressions for string literals of field names ($feature.Field or $feature["Field"]).

That approach fails when you request fields dynamically like you do here. In this case, Arcade (actually probably the Javascript controlling the popup) just doesn't load any fields, because it doesn't realize that you need them.

For cases like this, Arcade has the Expects() function. Here you can explicitly state which fields should be available. For convenience, you can also use a wildcard.

Just put this at the start of your expression:

Expects($feature, "*")

 


Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Frequent Contributor

This is intentional behavior.

For performance reasons, Arcade only loads the fields that are needed in the expression. It does that by checking the expressions for string literals of field names ($feature.Field or $feature["Field"]).

That approach fails when you request fields dynamically like you do here. In this case, Arcade (actually probably the Javascript controlling the popup) just doesn't load any fields, because it doesn't realize that you need them.

For cases like this, Arcade has the Expects() function. Here you can explicitly state which fields should be available. For convenience, you can also use a wildcard.

Just put this at the start of your expression:

Expects($feature, "*")

 


Have a great day!
Johannes
hoshijun
Emerging Contributor

Exactly what I needed. Thank you!

0 Kudos