I am using the following code to take two layers and merge into one table as a featureset.
//import
var portal = Portal('myportalurl');
var permitboundary_fs = FeatureSetByPortalItem(portal,'0ec1d6d3b5424618a0ac08129f7ac045',0,['name','area_acres'],false);
var disturbancearea_fs = FeatureSetByPortalItem(portal,'923a817eedd242d1af359a0963c6e9b0',0,['permitname','area_acres'],false);
//groupby
var permitboundary_final_fs = GroupBy(permitboundary_fs,'name',[{name: 'acrecalc', expression: 'area_acres', statistic: 'SUM'},])
var disturbancearea_final_fs = GroupBy(disturbancearea_fs,'permitname',[{name: 'acrecalc', expression: 'area_acres', statistic: 'SUM'},])
//create dictionary
var fsDict = {
'fields': [
{'name': 'permit_name', 'type': 'esriFieldTypeString' },
{'name': 'permit_acres','type': 'esriFieldTypeInteger'},
{'name': 'disturbance_acres','type': 'esriFieldTypeInteger'},
],
'geometryType': '',
'features': []
};
var index = 0
//loop to populate dictionary
for (var permitboundaryfinalfeat in permitboundary_final_fs) {
fsDict.features[index++] = {
'attributes': {
'permit_name': permitboundaryfinalfeat['name'],
'permit_acres': Round(permitboundaryfinalfeat['acrecalc'],0)
}
}
}
for (var disturbanceareafinalfeat in disturbancearea_final_fs) {
fsDict.features[index++] = {
'attributes': {
'permit_name': disturbanceareafinalfeat['permitname'],
'disturbance_acres': Round(disturbanceareafinalfeat['acrecalc'],0)
}
}
}
return FeatureSet(fsDict)
When i return the featureset it duplicates the area names and populates values for the second attribute, rather than just populating the records created during the first for loop. I think i need a if statement in the second for loop bur not sure of the syntax?