ESRI Javascript API Calculate Field

1100
5
Jump to solution
11-15-2016 01:37 PM
PaulVepraskas
Occasional Contributor

I need to reset all the values in a field for all the features in a feature service.  Just like the field Calculator in ArcMAP.  Basically push a button and a whole field gets reset?

Any ideas?

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

In one of my apps, I use applyEdits to update a collection of features (featureSet) with the click of a button. The user selected the new attributes from a series of combo boxes and clicked the button. In the button click function, my code looked like this

array.forEach(featureSet, function (feature) {
    feature.attributes.Priority = registry.byId('cboPriority').get("value");
    feature.attributes.Management = registry.byId('cboManagement').get("value");
    feature.attributes.Criteria = registry.byId('cboCriteria').get("value");
});

layerFeatureLayer.applyEdits(null, featureSet, null, function () { console.log("Features updated!"); }, function (error) { console.log("Features not updated! ", error); });

View solution in original post

5 Replies
RobertScheitlin__GISP
MVP Emeritus

Paul,

   This is not something that can be easily done in JS API. Your possibilities are to use FeatureLayer.applyEdits or create a GP service fro this.

0 Kudos
PaulVepraskas
Occasional Contributor

Thanks For the Reply Robert,

With the FeatureLayer.applyEdits is there a way to do all of the features at once or will I have to do each OBJECTID individually?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Paul,

   You have to provide an array containing each graphic (that is why I said that this is not easily done with JS API); 

0 Kudos
KenBuja
MVP Esteemed Contributor

In one of my apps, I use applyEdits to update a collection of features (featureSet) with the click of a button. The user selected the new attributes from a series of combo boxes and clicked the button. In the button click function, my code looked like this

array.forEach(featureSet, function (feature) {
    feature.attributes.Priority = registry.byId('cboPriority').get("value");
    feature.attributes.Management = registry.byId('cboManagement').get("value");
    feature.attributes.Criteria = registry.byId('cboCriteria').get("value");
});

layerFeatureLayer.applyEdits(null, featureSet, null, function () { console.log("Features updated!"); }, function (error) { console.log("Features not updated! ", error); });
PaulVepraskas
Occasional Contributor

That worked!  Thanks Ken! 

Did a query to select all features then ran that array.  Thank you

0 Kudos