Select to view content in your preferred language

Missing "Globals" in my data expression editor

4262
13
08-26-2021 07:44 AM
dstrigl
Regular Contributor

It looks like that inside the data expression editor of my sample ArcGIS Dashboard the "Globals" are missing

(as described in this video: https://www.youtube.com/watch?v=Dub1Ako2ljw&t=1008s😞Globals.png

Is there any setting or somethings else to get it?

Thanks and regards,

Daniel.

 

0 Kudos
13 Replies
by Anonymous User
Not applicable

Globals are not available in Data Expression.  You have to use FeatureSetbyPortal.  I'm struggling with data expressions myself.

https://www.esri.com/arcgis-blog/products/ops-dashboard/announcements/introducing-data-expressions-i...

dstrigl
Regular Contributor

Thanks for the info and the link!

I found the way of using FeatureSetbyPortal which works fine, but this means that's not possible to directly access the features of a allready included map of the dashboard.

I have to access it using FeatureSetbyPortal. It's ok for me, but doesn't really make sense for me why it's not possible to reference it using globals vars.

Another question: Have you ever created FeatureSets using data expression with domains?

I have the problem, that if I create a new FeatureSet with the data expressions from a FeatureSet which allready have a relation to a domain this git lost 😞 ...

Regards,

Daniel.

0 Kudos
by Anonymous User
Not applicable

I'm a novice when it comes to data expressions and arcade expressions.  Slowly improving!  My latest post is linked below, so hopefully my script can help you build yours!  

https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-for-pie-chart-in-dashboard...

@XanderBakker  is an excellent resource for Arcade and Data Expressions.  I'd highly recommend reviewing his posts and answers for more tips! 

 

 

dstrigl
Regular Contributor

Thanks a lot @Anonymous User 

XanderBakker
Esri Esteemed Contributor

Hi @dstrigl ,

Just a little note; since you create a FeatureSet you could include the domain definition in the creation process. However, it might be easier to create the field with the domain description rather than the domain code for visualization purposes. 

0 Kudos
dstrigl
Regular Contributor

Hi @XanderBakker,

thanks a lot for your hints!

However, it might be easier to create the field with the domain description rather than the domain code for visualization purposes. 

That's exactly what I am trying now ... something like that (using the function DomainName):

 

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

 

Is that the way you recommend, because it doesn't seem to work in my sample ...

But there is one additionally thing I found out. If I try the following:

 

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

 

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

 

ACCOUNT_MANAGER:
4
2
2
4
4
.
.
.

 

You have any idea why I didn't get the correct domain names?

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
XanderBakker
Esri Esteemed Contributor

Hi @dstrigl ,

 

I think this is caused by GroupBy function which will take the values of the account managers and not the descriptions. There are different ways to resolve this, but below you can see how you can create an intermediate dictionary and harvest the values that you need and write the result after this.

var p = Portal('https://www.arcgis.com'); 
var itemId = '???'; 
var layerId = 1; 
var fs = Filter(FeatureSetByPortalItem(p, itemId, layerId, ['ACCOUNT_MANAGER', 'REGION'], false), 'ACCOUNT_MANAGER > 0');

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


// create an intermediate dictionary 
// to store a list of unique regions per account manager
var d = {};
var l = [];
for (var f in fs) {
    var accman = DomainName(f, 'ACCOUNT_MANAGER');
    var region = f["REGION"];
    if (HasKey(d, accman)) {
        l = d[accman];
        Insert(l, 0, region);
    } else {
        l = [region];
    }
    d[accman] = Distinct(l);
}


// write the dictionary to the output featureset
var index = 0; 
for (var accman in d) { 
    dict.features[index] = { 
        'attributes': 
            {'ACCOUNT_MANAGER': accman, 
             'COUNT_REGIONS': Count(d[accman]), 
            }, 
    } 
    index++; 
}; 

return FeatureSet(Text(dict)); 
0 Kudos
dstrigl
Regular Contributor

Hi @XanderBakker,

thanks again for this well explained hint, but I think the problem why I didn't get the domain names are rooted in the base feature set I optain with the FeatureSetByPortalItem() function.

If I run the following script I still also doesn't get any domain names, although if I open the corresponding feature layer in the Map Viewer, the domain names are shown.

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

var fs = Filter(
            FeatureSetByPortalItem(portal, itemId, layerId, ['ACCOUNT_MANAGER', 'REGION'], false),
            'ACCOUNT_MANAGER > 0'
         );

for (var f in fs) {
    Console(f);
    var accman = DomainName(f, 'ACCOUNT_MANAGER');
    Console("DomainName: " + accman);
    Console("");
}

Messages:

Use Console Function to output messages.

{"geometry":null,"attributes":{"OBJECTID":721,"REGION":12345,"ACCOUNT_MANAGER":4}}
DomainName: 4

{"geometry":null,"attributes":{"OBJECTID":722,"REGION":12589,"ACCOUNT_MANAGER":2}}
DomainName: 2

{"geometry":null,"attributes":{"OBJECTID":723,"REGION":54216,"ACCOUNT_MANAGER":2}}
DomainName: 2

...

Any idea why the domain names are not part of the feature set optained by the FeatureSetByPortalItem() function?

Regards,

Daniel.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @dstrigl ,

I think it is not the FeatureSetByPortalItem() function that is doing this. I just did a small test (in a pop-up, not in a data expression) with this function and I have access to the domain after reading the featureset with the FeatureSetByPortalItem() function.

XanderBakker_0-1631562056119.png

 

So, could I wonder what is the data source of the data? Are you working with ArcGIS Online or with Enterprise (and if it is Enterprise, what version)?  When you include the expression in a pop-up do you have access to the domain? I will do a small check within a Dashboard because maybe it is something related to the way Arcade has been implemented in the Dashboards. 

0 Kudos