I am trying to remove the underscores from the split field, not all fields. I've been trying to do different things within my data expression but haven't gotten it to work yet.
// Split values corresponding to Target
// Reference layer using the FeatureSetByPortalItem() method.
var fs = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), 'aff5dd7c9615404cac256ec6dc627e10' , 0, ["*"], false);
// Empty dictionary to capture each target reported as separate rows.
var choicesDict = {'fields': [{ 'name': 'globalid', 'type': 'esriFieldTypeGlobalID'},
{ 'name': 'Name', 'type': 'esriFieldTypeString'},
{ 'name': 'Jurisdiction', 'type': 'esriFieldTypeString'},
{ 'name': 'Community', 'type': 'esriFieldTypeString'},
{ 'name': 'core_capability', 'type': 'esriFieldTypeString'},
{ 'name': 'split', 'type': 'esriFieldTypeString'},
{ 'name': 'Target', 'type': 'esriFieldTypeString'},
'geometryType': '',
'features': []};
// Split comma separated targets and store in dictionary.
for (var f in fs) {
var globalid = f["globalid"]
var Name = f["Name"]
var Jurisdiction = f["Jurisdiction"]
var Sub_Jurisdiction = f["Sub_Jurisdiction"]
var core_capability = f["core_capability"]
var Target = f["Target"]
var split_array = Split(f["target"], ',')
for(var i in split_array) {
Push(choicesDict.features, {"attributes":{
"globalid": globalid,
"Name": Name,
"Jurisdiction": Jurisdiction,
"Community": Sub_Jurisdiction,
"core_capability": core_capability,
"Target": Target,
"split": Trim(split_array[i])}})
}
}
//var result = Replace(choicesDict, "_", " ");
// Convert dictionary to featureSet.
var fs_dict = FeatureSet(Text(choicesDict));
return fs_dict
//Return featureset after grouping by sub topic
return GroupBy(fs_dict, ['split'],
[{ name: 'No', expression: 'split', statistic: 'COUNT' }]);
Solved! Go to Solution.
Can you just replace the underscore before you add it to the dictionary?
for(var i in split_array) {
var newSplit = Replace(split_array[i], '_', ' ');
Push(choicesDict.features, {"attributes":{
"globalid": globalid,
"Name": Name,
"Jurisdiction": Jurisdiction,
"Community": Sub_Jurisdiction,
"core_capability": core_capability,
"Target": Target,
"split": Trim(newSplit)}})
}
Can you just replace the underscore before you add it to the dictionary?
for(var i in split_array) {
var newSplit = Replace(split_array[i], '_', ' ');
Push(choicesDict.features, {"attributes":{
"globalid": globalid,
"Name": Name,
"Jurisdiction": Jurisdiction,
"Community": Sub_Jurisdiction,
"core_capability": core_capability,
"Target": Target,
"split": Trim(newSplit)}})
}
@KenBuja worked perfectly. Thanks!!