Returned FeatureSet from data expression with domain relation?

157
2
09-08-2021 04:36 AM
Labels (1)
dstrigl
New Contributor III

Dear Community,

I am playing around with the ArcGIS Dashboard and the data expression functionality ...

Now I am created a new FeatureSet using data expressions from an Layer with relation to a domain.

If I am presenting this FeatureSet in a list widget only the numeric values are presented and not the corresping domain values.

Is there a way to apply this domain to the new FeatureSet or any other recommended way?

Regards,

Daniel.

 

0 Kudos
2 Replies
jcarlson
MVP Regular Contributor

Other Recommended Way

There is a way of applying the domain to another object, but since you're working directly with the layer, it would be easier to use DomainName while building your FeatureSet. I imagine you're iterating through the layer and populated the FeatureSet's Features array, so it might look like this:

 

// Assuming vars 'lyr' and 'out_dict' represent your input layer and output dictionary which will be converted to a FeatureSet, respectively

var i = 0

for(var l in lyr){
    out_dict['features'][i] = {attributes: {'domain_field': DomainName(l, 'domain_field')}}
    i ++
}

fs = FeatureSet(Text(out_dict))

 

Applying a Domain to a FeatureSet

See the Arcade function Domain. If you use this on your layer first, it returns a dictionary representing the domain for a given field. The example on the linked page looks like this:

{
  type: "codedValue" ,
  name: "poleTypes",
  dataType: "number",
  codedValues: [
    { name: "Unknown", code: 0 },
    { name: "Wood", code: 1 },
    { name: "Steel", code: 2 }
  ]
}

When creating the FeatureSet (or rather, the dictionary that will become your FeatureSet), you establish the fields array. Within a given field, you can simply append the domain returned from this function, as the domain is a property of a field. This can be done before populating the features.

 

// Assuming var 'lyr' is your input layer

var dom = Domain(lyr, 'domain_field')

var out_dict = {
    'fields': [{
        'name': 'domain_field',
        'type': 'esriFieldTypeInteger',
        'domain': dom
    }],
    'geometryType': '',
    'features': []
}

// Populate your FeatureSet as usual, domain should apply

 

 

- Josh Carlson
Kendall County GIS
0 Kudos
dstrigl
New Contributor III

Hi @jcarlson,

thanks a lot for your help.

The way with the DomainName() function is exactly what I am trying now:

 

var portal = Portal('https://www.arcgis.com');
var itemId = '???';
var layerId = 1;

var fs = GroupBy(
    Filter(
        FeatureSetByPortalItem(portal, itemId, layerId, ['ACCOUNT_MANAGER', 'REGION'], false),
        'ACCOUNT_MANAGER > 0'),
    ['ACCOUNT_MANAGER'],
    [
        { name: 'COUNT_REGIONS', expression: 'REGION', statistic: 'COUNT' },
    ]);

var dict = {
    'fields': [
        { 'name': 'ACCOUNT_MANAGER', 'type': 'esriFieldTypeString' },
        { 'name': 'COUNT_REGIONS', 'type': 'esriFieldTypeInteger' },
    ],
    'geometryType': '',
    'features': []
    };

var index = 0;
for (var f in fs) {
    dict.features[index] = {
        'attributes': {
            'ACCOUNT_MANAGER': DomainName(f, 'ACCOUNT_MANAGER'),
            'COUNT_REGIONS': f['COUNT_REGIONS'],
        },
    };
    index++;
}

return FeatureSet(Text(dict));

 

But this seems to doesn't work in my sample :(

Additionally I tested the following:

 

var fs = FeatureSetByPortalItem(...);
Console("ACCOUNT_MANAGER:");
for (var f in fs) {
    var d = DomainName(f, "ACCOUNT_MANAGER");
    Console(d);
}

 

and I only get the numeric values and NOT the names represented by the domain!

 

ACCOUNT_MANAGER:
4
2
2
4
4
.
.
.

 

Do you have any idea what's wrong?

The names are still in the layer, because if I open the table inside the Map Viewer I will see it ...

Some note: Could it be a problem that the table which includes the  ACCOUNT_MANAGER has a subtype?

Regards,

Daniel.

0 Kudos