Hello All!
I am looking to write a data expression that takes an attribute field from the hosted table and creates a new field with a new assigned value based on the value from the field I am pulling from. However, I cannot seem to get this expression to run correctly. Any help and corrections to get this expression to run is very much appreciated. Thank you! Below is my code:
var fs = FeatureSetByPortalItem(
portal,
'155af3e091404240acd2904e34a07bf6',
0,
['Contest_title'],
false
);
// Create empty array for features and feat object
var features = [];
var feat;
// Split comma separated hazard types and store in dictionary.
for (var feature in fs) {
if ($feature["Contest_title"] == "President of the United States (REP)" ) {return "A"}
if ($feature["Contest_title"] == "United States Senator (REP)" ) {return "C"}
if ($feature["Contest_title"] == "Attorney General (REP)" ) {return "E"}
if ($feature["Contest_title"] == "Auditor General (REP)" ) {return "G"}
if ($feature["Contest_title"] == "State Treasurer (REP)" ) {return "I"}
if ($feature["Contest_title"] == "Representative in Congress -13th District (REP)" ) {return "K"}
if ($feature["Contest_title"] == "Representative in the General Assembly -78th District (REP)" ) {return "O"}
if ($feature["Contest_title"] == "Delegate to the Republican National Convention (REP)" ) {return "M"}
if ($feature["Contest_title"] == "Alternate Delegate to the Republican National Convention (REP)" ) {return "P"}
if ($feature["Contest_title"] == "Republican Committee Person - Bedford Borough West (REP)" ) {return "Q"}
if ($feature["Contest_title"] == "Republican Committee Person - Bedford Township 1 (REP)" ) {return "R"}
if ($feature["Contest_title"] == "Republican Committee Person - Bedford Township 2 (REP)" ) {return "S"}
if ($feature["Contest_title"] == "Republican Committee Person - Everett Borough (REP)" ) {return "T"}
if ($feature["Contest_title"] == "Republican Committee Person - Hopewell Township (REP)" ) {return "U"}
if ($feature["Contest_title"] == "Republican Committee Person - King Township (REP)" ) {return "V"}
if ($feature["Contest_title"] == "Republican Committee Person - West Providence Township (REP)" ) {return "W"}
if ($feature["Contest_title"] == "Republican Committee Person - West St. Clair Township (REP)" ) {return "X"}
if ($feature["Contest_title"] == "Republican Committee Person - Woodbury Township (REP)" ) {return "Y"}
if ($feature["Contest_title"] == "President of the United States (DEM)" ) {return "B"}
if ($feature["Contest_title"] == "United States Senator (DEM)" ) {return "D"}
if ($feature["Contest_title"] == "Attorney General (DEM)" ) {return "F"}
if ($feature["Contest_title"] == "Auditor General (DEM)" ) {return "H"}
if ($feature["Contest_title"] == "State Treasurer (DEM)" ) {return "J"}
if ($feature["Contest_title"] == "Representative in Congress -13th District (DEM)" ) {return "L"}
if ($feature["Contest_title"] == "Delegate to the Democratic National Convention (DEM)" ) {return "N"}
else {return "Unsatisfactory"}
}
Push(features, feat);
}}
// Empty dictionary to capture each hazard reported as separate rows.
var choicesDict = {
'fields': [
{ 'name': 'Contest_ID', 'type': 'esriFieldTypeString'}],
'geometryType': '',
'features': features
};
// Convert dictionary to featureSet.
var fs_dict = FeatureSet(Text(choicesDict));
// Return featureset after grouping by hazard types.
return GroupBy(fs_dict, ['Contest_ID'],
[{ name: 'Contest_ID', expression: 'Contest_ID', statistic: 'MAX' }]);