Popup Template is unable to render arcade expression

1062
1
11-05-2019 12:30 AM
AshleyOng
New Contributor

Hi everyone,

I am using Arcgis API for JS v4.13 to create a web application. I have a MapImageLayer created from a service url, which contains 4 sublayers:

var MyLayer = new MapImageLayer({
    url: 'https://url/to//MapServer/',
    sublayers: [
        {
            id: 5,
            visible: true,
            title: 'abc'
        },
        {
            id: 4,
            visible: true,
            title: 'def'
        },
        {
            id: 3,
            visible: true,
            title: 'ghi',
            popupTemplate: customPopupThird
        },
        {
            id: 1,
            visible: true,
            title: 'jkl',
            popupTemplate: customPopupFourth
        }
    ]
});
For my first popupTemplate, the arcade expression inside works, but for customPopupFourth, it doesn't work. Below is the popuptemplate that doesn't work.
title: 'Title for layer id 1',
outFields: ['*'],
expressionInfos: [
        {
            name: 'CurLandAreatoHect',
            title: 'Current Land Area (ha)',
            expression: '$feature.CurLandArea / 10000'
        }
],
content: [
        {
            type: 'fields',
            fieldInfos: [
                {
                    fieldName: 'expression/CurLandAreatoHect'
                }
            ]
        }
    ]
The console from the browser throws up this error:
Logger.js:25 [esri.widgets.FeatureViewModel] query-required-fields Could not query required fields for the specified layer. Some fields will not be available.
and
Logger.js:25 [esri.widgets.FeatureViewModel] arcade-execution-error TypeError: Cannot read property 'length' of undefined
at t._fixDates (Feature.js:25)
at t.field (Feature.js:25)
at Object.member (arcadeCompiler.js:25)
at eval (eval at he (arcadeCompiler.js:25), <anonymous>:10:34)
at Generator.next (<anonymous>)
at arcadeCompiler.js:25
at new Promise (<anonymous>)
at Object.v [as create] (promiseUtils.js:25)
at Object.__awaiter (arcadeCompiler.js:25)
at mainBody (eval at he (arcadeCompiler.js:25), <anonymous>:9:14)
The resulting field in the table generated in the popup will be blank because of this error.
Thank you!
0 Kudos
1 Reply
sorelkebeq
New Contributor

I think there is a bug in Version 4.13 of the JSAPI. I am not using Arcade Expressions but I do get the same 'query-required-fields Could not query required fields for the specified layer. Some fields will not be available' warning in the console.

It seems to be related to using the "outFields: ['*']" property value pair on a MapImageLayer

The following codepen throws warnings in the console (click on a blue dot first), if you switch the script and stylesheet tags to point to JSAPI V 4.12 the warnings go away. The other way to get rid of the warning is to specify outFields explicitly rather than '*'

https://codepen.io/sorel/pen/abbRJRo 

0 Kudos