How to use ArcGIS uniqueValues For two Fields in ArcGIS JavaScript API

Viewed 12

Using ArcGIS JavaScript API 4.24 and uniqueValues from esri/smartMapping/statistics/uniqueValues I am able to get Count of all features in a FeatureLayer (fcLayer in this code)

In this example respond is based on AppType field from fcLayer

            uniqueValues({
                layer: fcLayer,
                field: "AppType",
            }).then(function(response) {
                let infos = response.uniqueValueInfos;
                infos.forEach(function(info) {
                    console.log("Application Type: ", info.value, " are: ", info.count);
                });
            });

enter image description here

Now Can you please let me know how I can robust this code in a way that I can group and query two fields AppType and AppStat instead of field: "AppType" only?

I tried to use sqlExpression and sqlWhere instead of field option like

sqlExpression = "AppType = 'RD' AND AppStat = 'active'"
sqlWhere = "AppType = 'RD' AND AppStat = 'active'"

in the code like

        uniqueValues({
            layer: fcLayer,
            sqlExpression = "AppType = 'RD' AND AppStat = 'active'"
        }).then(function(response) {

or

        uniqueValues({
            layer: fcLayer,
            sqlWhere= "AppType = 'RD' AND AppStat = 'active'"
        }).then(function(response) {

But none of them returning any thing!

1 Answers

I think you need to use valueExpression to achieve what you want. This should result in a string or a number wich will be use to calculate the unique values. I guess something like this should work,

uniqueValues({
    layer: fcLayer,
    valueExpression = "Concatenate([$feature.AppType, $feature.AppStat], '_')"
}).then(...)

In the expression example above I concatenate both fields with '_' character.

Related