Hello!
I am not sure this is even possible, but...
I am using a client's dataset which I can't edit, otherwise I would just create a new field in the actual data. I need to multiply one field by the percentage of another and display a table that shows GroupedBy status elements. Below is the code that I have so far...please let me know if there are any ideas.
var fs = FeatureSetByPortalItem(
Portal('https://xyz'),
'05b99d65195e41x5b1f49436eea53bfb',
0,
['PermitCurrentStatus', 'TotalLand', 'UndividedInterest'],
false
);
var field1 = 'TotalLand',
var field2 = 'UndividedInterest',
var trueacreage = field2/100 * field1
return GroupBy(fs, ['PermitCurrentStatus', 'UndividedInterest','TotalLand'],
[{name: 'TotalLand_count', expression: 'TotalLand', statistic: 'SUM'},
{name: 'trueacres', expression: 'trueacreage', statistic: 'SUM'},
{name: 'UndividedInterestCount', expression: 'UndividedInterest', statistic: 'SUM'}]);
It's possible but I'm not sure if it can be done as concisely as your group-by function there.
I think you might need to iterate through your feature set, derive each feature's new attribute one-by-one, construct a new feature and add it to a list, then convert your list to a feature set.
Deriving a new feature and adding it to a list would look like this:
var featureList = [];
for (var feature in featureSet) {
var newFeature = {
attributes: {
value1: feature.value1,
value2: feature.value2,
derived: feature.value1 / feature.value2
}
}
Push(featureList, newFeature);
}
Once you've got your new features in a list, you can return your new feature set by defining its schema like this:
var returnFeatureSetDict = {
fields: [
{ name: "value1", type: "esriFieldTypeInteger" },
{ name: "value2", type: "esriFieldTypeInteger" },
{ name: "derived", type: "esriFieldTypeDouble" }
],
"geometryType": "",
"features": featureList
};
return FeatureSet(Text(returnFeatureSetDict));
(I'm not actually testing this code as I'm writing it, I'm just typing it freehand, so it might have some bugs but should get the pattern across.)
There very well could be a quicker way to do this, but I think this should work at least.