Hello,
I am using Arcade in Dashboard on a list Widget. I am pulling information from a survey 123. The Surveys first Question, depending on the answer, uncovers a select multiple question ( I have 9 in total) which gives you an array with the selected towns. The problem is when submitter of the survey submits again and selects the same towns . Towns are duplicated. I have a arcade code that will put each select by many into its own field in a featureSet but, still show the duplicates and wont pull the answer from the Field one(first question in survey). Ultimately I just need the count of towns for each select by many choice, to be displayed in the list.
code:
var vportal = Portal('https://www.arcgis.com');
var fs = FeatureSetByPortalItem(
vportal,
'Item_ID',
0,
["Field1","Field2","Field3","Field4"],
false
);
// Create empty array for features
var features = [];
// Loop through each feature in the feature set.
for (var vfeature of fs) { // Corrected loop
var split_array = Split(vfeature['Field2'], ',', -1, true);
var count_arr = Count(split_array);
// Loop through the split values.
for (var i = 0; i < count_arr; i++) {
var exists = false;
// Check if the feature already exists in the features array.
for (var existingFeature of features) { // Corrected loop for checking existing features
if (existingFeature.attributes['split_choices_Field2'] == Trim(split_array[i])) {
exists = true;
break;
}
}
// Add the feature only if it doesn't already exist.
if (!exists) {
var feat = {
'attributes': {
'Region': vfeature['Field1'],
'split_choices_Field2': Trim(split_array[i]),
'northeastern_connecticut_towns': vfeature['Field2']
}
};
Push(features, feat);
}
}
}
// Create the dictionary to capture each hazard as separate rows.
var choicesDict = {
'fields': [
{ 'name': 'Region', 'type': 'esriFieldTypeString' },
{ 'name': 'split_choices_Field2', 'type': 'esriFieldTypeString' }
],
'geometryType': '',
'features': features
};
// Convert dictionary to FeatureSet.
var fs_dict = FeatureSet(choicesDict.features);
return fs_dict;
I have also tried :
var vportal = Portal('https://www.arcgis.com')
var fs = FeatureSetByPortalItem(
vportal,
'Item_ID',
0,
["Field1","Field2","Field3","Field4"],
false
);
//return fs
// Create empty array for features and feat object
var features = [];
var feat;
// Split comma separated hazard types and store in dictionary.
for (var vfeature in fs) {
var split_array = Split(vfeature["Field2"], ',',-1,true)
var count_arr = Count(split_array)
for(var i = 0; i < count_arr; i++ ){
feat = {
'attributes': {
'Region':vfeature.Field1,
'split_choices_Field2': Trim(split_array[i]),
'towns_Field2':vfeature.Field2
}
}
Push(features, feat);
}}
// Empty dictionary to capture each hazard as separate rows.
var choicesDict = {
'fields': [
{'name': 'Region', 'type': 'esriFieldTypeString'},
{ 'name': 'split_choices_Field2', 'type': 'esriFieldTypeString'}],
'geometryType': '',
'features': features
};
// Convert dictionary to featureSet.
var fs_dict = FeatureSet(Text(choicesDict));
return fs_dict