Dashboard Data Expression Survey Date List from All AGOL Survey Feature Layers for Category Selector

572
2
Jump to solution
03-15-2022 01:16 PM
kmsmikrud
Occasional Contributor III

Hello,

I am working on a dashboard with a category selector to show survey data by survey date. Instead of selecting just one data source in case no data was collected for that layer I would like to be able to set a data expression as the source, that way I do not miss showing survey data on the dashboard.

There are 5 survey data layers and I can pull in the dates as a FeatureDataset for each of the data layers (like below), but I'm having trouble combining all the data sources and to get a distinct survey date list. I'm not sure where to go after I get the individual layer dates.

Do I need to make a list from the FeatureDataset or please advise. I am not very versed in arcade.

 

var fs = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), 'xxxxxxx', 0, ["AKDate"], false);
var track_dt = Distinct(fs,["AKDate"]);

 

@XanderBakker you have been such a great help in the past, any suggestions on the arcade syntax? Thank-you!

Thanks in advance!

Kathy

0 Kudos
1 Solution

Accepted Solutions
kmsmikrud
Occasional Contributor III

Thanks to other posts on Community this code works! Might not be the most efficient but it works!

var fs = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), 'xxxxx', 0, ["AKDate"], false);
var track_dt = Distinct(fs,["AKDate"]);

var fs2 = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), 'xxxxxx', 2, ["AKDate"], false);
var spawn_dt = Distinct(fs2, ["AKDate"]);

var fs3 = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), 'xxxxxx', 1, ["AKDate"], false);
var pred_dt = Distinct(fs3, ["AKDate"]);
//return track_dt

var fs4 = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), 'xxxxx', 0, ["AKDate"], false);
var hschool_dt = Distinct(fs4, ["AKDate"]);


var Dict = {
    'fields':[
        {'name': 'AKDate', 'type': 'esriFieldTypeString'}
],
'geometryType': '',
'features':[]
};

var i = 0;
for (var f in track_dt){
    Dict.features[i] = {
        'attributes':{
            'AKDate': f['AKDate'],
        }
    };
    i++;
}
for (var f in spawn_dt){
    Dict.features[i] = {
        'attributes':{
            'AKDate': f['AKDate'],
        }
    };
    i++;
}

for (var f in pred_dt){
    Dict.features[i] = {
        'attributes':{
            'AKDate': f['AKDate'],
        }
    };
    i++;
}

for (var f in hschool_dt){
    Dict.features[i] = {
        'attributes':{
            'AKDate': f['AKDate'],
        }
    };
    i++;
}

Console(Text(Dict))
var s_dt = FeatureSet(Text(Dict));
return Distinct(s_dt,['AKDate']);

View solution in original post

0 Kudos
2 Replies
kmsmikrud
Occasional Contributor III

Hello,

An update, I found in searching other posts similar syntax below to create a list. Below shows creating a list of survey dates just from one layer. My plan would be to bring in the other survey layers and then similarly add to the list, get distinct values and have the category selector use the data expression.

Currently below the code returns a list of survey dates within the one layer when I test it, but outside of the data expression I get the yellow exclamation, "Unable to execute arcade script". I understand for the data expression the output needs to return a FeatureSet. How do I convert the list to a FeatureSet? 

Thanks!

 

var fs = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), 'xxxxxx', 0, ["AKDate"], false);
var track_dt = Distinct(fs,["AKDate"]);
//return track_dt

var sdate_lst = []
for (var dt in track_dt){
    Push(sdate_lst, dt.AKDate)
}

return Concatenate(sdate_lst, '\n')

 

 

0 Kudos
kmsmikrud
Occasional Contributor III

Thanks to other posts on Community this code works! Might not be the most efficient but it works!

var fs = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), 'xxxxx', 0, ["AKDate"], false);
var track_dt = Distinct(fs,["AKDate"]);

var fs2 = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), 'xxxxxx', 2, ["AKDate"], false);
var spawn_dt = Distinct(fs2, ["AKDate"]);

var fs3 = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), 'xxxxxx', 1, ["AKDate"], false);
var pred_dt = Distinct(fs3, ["AKDate"]);
//return track_dt

var fs4 = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), 'xxxxx', 0, ["AKDate"], false);
var hschool_dt = Distinct(fs4, ["AKDate"]);


var Dict = {
    'fields':[
        {'name': 'AKDate', 'type': 'esriFieldTypeString'}
],
'geometryType': '',
'features':[]
};

var i = 0;
for (var f in track_dt){
    Dict.features[i] = {
        'attributes':{
            'AKDate': f['AKDate'],
        }
    };
    i++;
}
for (var f in spawn_dt){
    Dict.features[i] = {
        'attributes':{
            'AKDate': f['AKDate'],
        }
    };
    i++;
}

for (var f in pred_dt){
    Dict.features[i] = {
        'attributes':{
            'AKDate': f['AKDate'],
        }
    };
    i++;
}

for (var f in hschool_dt){
    Dict.features[i] = {
        'attributes':{
            'AKDate': f['AKDate'],
        }
    };
    i++;
}

Console(Text(Dict))
var s_dt = FeatureSet(Text(Dict));
return Distinct(s_dt,['AKDate']);
0 Kudos