@KenBuja So this works to create a dictionary representing the data I need, but I am not able to successfully convert into a featureSet for use within dashboards. I believe I need to add the relevant fields that would be in the JSON, and add the dictionary essentially as features -- but I'm having trouble doing this. I'll attach my code, but it is not successfully replicating the dictionary nor is it able to be converted to a featureset using the FeatureSet() function.
//SECOND ATTEMPT: this time trying to add directly to a fs compatible dicitonary
var fs1 = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), '2284118eba59466e9169133c458ef9d4' , 0, ['development_priorities'], false);
var choicesArray1 = []
// return fs
// Split comma separated hazard types and store in array.
for (var f in fs1) {
var split_array1 = Split(f["development_priorities"], ',');
var choiceArray1 = []
for (var index in split_array1) push(choiceArray1, split_array1[index]);
push(choicesArray1, choiceArray1); //add this to final array
}
//return(choicesArray1)
var valuecounts1={
'fields':[
{'name':'First Choice','type':'esriFieldTypeInteger'},
{'name':'Second Choice','type':'esriFieldTypeInteger'},
{'name':'Third Choice','type':'esriFieldTypeInteger'},
{'name':'Fourth Choice','type':'esriFieldTypeInteger'},
{'name':'Fifth Choice','type':'esriFieldTypeInteger'},
{'name':'Sixth Choice','type':'esriFieldTypeInteger'},
{'name':'Quality','type':'esriFieldTypeString'},
{'name':'Average','type':'esriFieldTypeFloat'}
],
'geometryType':'',
'features':[]
};
//return(valuecounts1)
valuecounts1.features[0]= {'Quality':"transportation",'First Choice': 0,'Second Choice' : 0,'Third Choice' : 0,'Fourth Choice' : 0,'Fifth Choice' : 0,'Sixth Choice' : 0,'Average' : 0}
valuecounts1.features[1]= {'Quality':"jobs",'First Choice': 0,'Second Choice' : 0,'Third Choice' : 0,'Fourth Choice' : 0,'Fifth Choice' : 0,'Sixth Choice' : 0,'Average': 0}
valuecounts1.features[2]= {'Quality':"housing",'First Choice': 0,'Second Choice' : 0,'Third Choice' : 0,'Fourth Choice' : 0,'Fifth Choice' : 0,'Sixth Choice' : 0,'Average':0}
valuecounts1.features[3]= {'Quality':"sustainability",'First Choice': 0,'Second Choice' : 0,'Third Choice' : 0,'Fourth Choice' : 0,'Fifth Choice' : 0,'Sixth Choice' : 0,'Average':0}
valuecounts1.features[4]= {'Quality':"historical",'First Choice': 0,'Second Choice' : 0,'Third Choice' : 0,'Fourth Choice' : 0,'Fifth Choice' : 0,'Sixth Choice' : 0,'Average':0}
valuecounts1.features[5]= {'Quality':"parks",'First Choice': 0,'Second Choice' : 0,'Third Choice' : 0,'Fourth Choice' : 0,'Fifth Choice' : 0,'Sixth Choice' : 0,'Average':0}
//return(valuecounts1)
for (var a in choicesArray1) { //for each feature within the dataset
var choices = choicesArray1[a] //set choices as a variable representing the current feature which has 6 fields, a field for each choice
for(var i in choices) { //for each field within the current feature, rank 1, rank 2, etc..
var value = choices[i] //set value as the field within the feature
//add 1 to value counts for each time the feature exists??
var vcf = valuecounts1.features[i]
var vcfq = vcf['Quality']
//return(vcf['Quality'])
if(IsEmpty(value)) { continue }
if(vcfq == value) {
//if(!HasKey(value_counts, value)) { value_counts[value][i] = 0 } ignoring non-present values for now
if (i == 0) vcf['First Choice'] = vcf['First Choice'] + 1
if (i == 1) vcf['Second Choice'] = vcf['Second Choice'] + 1
if (i == 2) vcf['Third Choice'] = vcf['Third Choice'] + 1
if (i == 3) vcf['Fourth Choice'] = vcf['Fourth Choice'] + 1
if (i == 4) vcf['Fifth Choice'] = vcf['Fifth Choice'] + 1
if (i == 5) vcf['Sixth Choice'] = vcf['Sixth Choice'] + 1
}
}
}
return(valuecounts1)
//Console(valuecounts1)
// var fs2 = FeatureSet(Text(valuecounts1))
// return fs2
// NEW Get average value and append
for (var a in valuecounts1) {
vcf=valuecounts1.features[a]
vcf['Average']=(valuecounts1.features[a]['First Choice']*6+valuecounts1.features[a]['Second Choice']*5+valuecounts1.features[a]['Third Choice']*4+valuecounts1.features[a]['Fourth Choice']*3+valuecounts1.features[a]['Fifth Choice']*2+valuecounts1.features[a]['Sixth Choice'])/Count(fs1)
}
return(valuecounts1)
Console(valuecounts1)
var fs2 = FeatureSet(Text(valuecounts1))
return fs2