Hello,
I don't know anything in Arcade but I am following someone else code to split the answer of a multiselect question and generate a chart that counts each answer separatly.
The code is as follow
Could anyone help me in fixing it knowing that I don't know anything about arcade.
Thank you
Solved! Go to Solution.
The code does work substituting my own portal item. Where is it breaking for you? Are you checking the output at various places in the code with Console to see if it's returning what you're expecting?
var p = Portal("https://noaa.maps.arcgis.com/");
var fs = FeatureSetByPortalItem(
p,
'1624f1a86dca4af086cc13141a1b0e2b',
1,
['Authors'],
false
);
// Create empty array for features and feat object
var features = [];
var feat;
// Split comma separated hazard types and store in dictionary.
for (var feature in fs) {
var split_array = Split(feature["Authors"], ',')
var count_arr = Count(split_array)
console(count_arr)
for(var i = 0; i < count_arr; i++ ){
feat = {
'attributes': {
'split_choices': Trim(split_array[i])
}
}
Push(features, feat);
}}
// Empty dictionary to capture each hazard reported as separate rows.
var choicesDict = {
'fields': [
{ 'name': 'split_choices', 'type': 'esriFieldTypeString'}],
'geometryType': '',
'features': features
};
// Convert dictionary to featureSet.
var fs_dict = FeatureSet(choicesDict);
//return fs_dict
// Return featureset after grouping by hazard types.
return GroupBy(fs_dict, ['split_choices'],
[{ name: 'split_count', expression: 'split_choices', statistic: 'COUNT' }]);
That's not an error, but a warning. You shouldn't use reserved words as variable names. It will still work, but it might cause problems.
Thank you for your response.
Unfortunately it then don't allow me to progress further and select the expression to build my chart
The code does work substituting my own portal item. Where is it breaking for you? Are you checking the output at various places in the code with Console to see if it's returning what you're expecting?
var p = Portal("https://noaa.maps.arcgis.com/");
var fs = FeatureSetByPortalItem(
p,
'1624f1a86dca4af086cc13141a1b0e2b',
1,
['Authors'],
false
);
// Create empty array for features and feat object
var features = [];
var feat;
// Split comma separated hazard types and store in dictionary.
for (var feature in fs) {
var split_array = Split(feature["Authors"], ',')
var count_arr = Count(split_array)
console(count_arr)
for(var i = 0; i < count_arr; i++ ){
feat = {
'attributes': {
'split_choices': Trim(split_array[i])
}
}
Push(features, feat);
}}
// Empty dictionary to capture each hazard reported as separate rows.
var choicesDict = {
'fields': [
{ 'name': 'split_choices', 'type': 'esriFieldTypeString'}],
'geometryType': '',
'features': features
};
// Convert dictionary to featureSet.
var fs_dict = FeatureSet(choicesDict);
//return fs_dict
// Return featureset after grouping by hazard types.
return GroupBy(fs_dict, ['split_choices'],
[{ name: 'split_count', expression: 'split_choices', statistic: 'COUNT' }]);
Thank you very much - I have figured my error - I used to ID of the form not the result layers and it works
Another questions - my overall dashboard has date and category selectors in the heading section. Is there a way to include them in the expression so that the selectors will work on it?
Thank you very much