We have a working script to split apart values from a field that's the result of a multi-pick survey123 question. The resulting table has three fields with a row for each answer, and we use the script in a Dashboard. We tried adjusting this script to work in a different dashboard with a different feature service, but it's only returning empty fields.
They seem to be doing the same things, and I believe the punctuation is all the same as well. The main difference I can see is the non-working script is trying to use a date field where the working script is using a second string field. So maybe this could be causing a problem. But if so, I'm not sure how to fix it.
Anyone have any idea?
Working Script:
// Write an expression that returns a FeatureSet.
// Documentation: https://arcg.is/3c419TD
// Samples: https://arcg.is/38SEWWz
// Reference layer using the FeatureSetByPortalItem() method.
var vportal = Portal('https://www.arcgis.com')
var fs = FeatureSetByPortalItem(
vportal,
'3b33e05c548a4688ba8852a1053f580b',
0,
['severe_hazard_items_avail','City'],
false
);
// 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["severe_hazard_items_avail"], ',')
var count_arr = Count(split_array)
for(var i = 0; i < count_arr; i++ ){
feat = {
'attributes': {
'split_choices': Trim(split_array[i]),
'City':vfeature.City
}
}
Push(features, feat);
}}
// Empty dictionary to capture each hazard as separate rows.
var choicesDict = {
'fields': [
{ 'name': 'split_choices', 'type': 'esriFieldTypeString'},
{ 'name': 'City', 'type': 'esriFieldTypeString'}],
'geometryType': '',
'features': features
};
// Convert dictionary to featureSet.
var fs_dict = FeatureSet(Text(choicesDict));
return fs_dict
// Reference layer using the FeatureSetByPortalItem() method.
var vportal = Portal('https://www.arcgis.com')
var fs = FeatureSetByPortalItem(
vportal,
'd9ee252d54894d7980539078681775ee',
0,
['training_types', '_date'],
false
);
// 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["training_types"], ',')
var count_arr = Count(split_array)
for(var i = 0; i < count_arr; i++ ){
feat = {
'attributes': {
'split_choices': Trim(split_array[i]),
'_date':vfeature._date
}
}
Push(features, feat);
}}
// Empty dictionary to capture each choice as separate rows.
var choicesDict = {
'fields': [
{ 'name': 'split_choices', 'type': 'esriFieldTypeString'},
{ 'name': 'date', 'type': 'esriFieldTypeDate'}],
'geometryType': '',
'features': features
};
// Convert dictionary to featureSet.
var fs_dict = FeatureSet(Text(choicesDict));
return fs_dict