Select to view content in your preferred language

Removing underscores from single field with a data expression that uses split function

600
2
Jump to solution
06-03-2024 08:19 AM
dwold
by
Frequent Contributor

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' }]);

dwold_0-1717427812698.png

 

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

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)}})
  }

 

 

View solution in original post

2 Replies
KenBuja
MVP Esteemed Contributor

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)}})
  }

 

 

dwold
by
Frequent Contributor

@KenBuja worked perfectly. Thanks!!

0 Kudos