Hi, I am still having issues with this expression. I'd like to join a table to a GroupBy table (polygon feature layer) using JoinLayerFieldsToTable. I am able to import the Feature Layer and Table using FeatureSetByPortalItem. I am also able to GroupBy the 'Jurisdiction' column for my feature layer. I am just unsure where I am going wrong with the populate feature array, joining dictionary, and successfully returning the dictionary as a FeatureSet. Please see source code below. Again, I appreciate any helpful insights or solutions. Thanks.
// Write an expression that returns a FeatureSet.
// Documentation: https://arcg.is/3c419TD
// Samples: https://arcg.is/38SEWWz
var portal = Portal("https://marincounty.maps.arcgis.com/");
var polyFs = FeatureSetByPortalItem(portal,"1112f6fa268c48948093050fe0fc0c44",0,["*"],true);
var tablefs = FeatureSetByPortalItem(portal, "1093d97dbe43474b96d09b701d9672a1", 1,["Jurisdiction","Population","ProcurementTarget","uniqueID"],false);
// create grouped table variable
var polyGroup = GroupBy(polyFs,
['Jurisdiction'],
[{name:'SumPotentialCompTons', expression: "PotentialCompTons", statistic: 'SUM'},
{name:'SumPotentialMulchTons', expression: "PotentialMulchTons", statistic: 'SUM'},
{name:'SumPotentialROWPTons', expression: "TotPotentialROWPTons", statistic: 'SUM'}]);
// create empty features
var features = [];
var feat;
// populate feature array
for (var t in tablefs){
var tableID = t["uniqueID"]
for (var p in Filter(polyGroup, "Jurisdiction = "+tableID)){
feat = {
attributes: {
FeatureID: tableID,
Name: p["Jurisdiction"],
PotCompTons: p["SumPotentialCompTons"],
PotMulchTons: p["SumPotentialMulchTons"],
PotROWPTons: p["SumPotentialROWPTons"],
Population: t["Population"],
ProcurementTarget: t["ProcurementTarget"],
}
}
Push(features,feat)
}
}
var joinedDict = {
fields: [
{ name: "FeatureID", type: "esriFieldTypeInteger" },
{ name: "Name", type: "esriFieldTypeString" },
{ name: "PotCompTons", type: "esriFieldTypeDouble" },
{ name: "PotMulchTons", type: "esriFieldTypeDouble" },
{ name: "PotROWPTons", type: "esriFieldTypeDouble" },
{ name: "Population", type: "esriFieldTypeInteger" },
{ name: "ProcurementTarget", type: "esriFieldTypeDouble" },
],
'geometryType': '',
'features':features
};
// return dict as feature set
return FeatureSet(joinedDict);