applyEdits attributes not updating

824
1
03-01-2021 10:32 PM
LisaT
by
Occasional Contributor II

I am trying to add new features to a hosted feature service via a custom tool in Portal (currently Enterprise 10.7.1).  I am using "applyEdits". It is setting the geometry, but I can't seem to get my code to also set the attributes.  I have tried many things (see my commented-out code) but the result is always that the geometry is added without any attributes. An objectid is auto-calculated. I have created a featureclass with one text attribute.  Here is the code I have tried:

var hostfeatureLayer = new FeatureLayer("https://ourCompany.domain/arcgis/rest/services/Hosted/myTest_featureClass/FeatureServer/0");

let features = [];

var attr = { "testText": "Mesa Mint" };
let graphic = new Graphic(geometry, null, attr);

 

//Ive also tried:
// let attr = {};
// attr.testText = "tester";

//let graphic = new Graphic({
// geometry: geometry,
// attributes: {
// "testText": "test"
// }
//});


// let graphic = new Graphic(geometry);
// graphic.setAttributes(attr);

// graphic.attributes["testText"] = "tester";

features.push(graphic);

hostfeatureLayer.applyEdits(features, null, null).then(function (adds, updates, deletes) {
console.log('success', adds);
}, function (err) {
console.log(err);
});

 

In looking at all of the code samples, one of these should work.  When looking at the graphic properties after it is created, many of these attempts correctly fill in the "attributes" property of the Graphics object.  However, "applyEdits" doesn't apply them! If I put a breakpoint on the "console.log('success' line, the "add" object does not show any attributes.  Any ideas what I am doing wrong here?  The hosted feature service is set up for add, update and delete.

0 Kudos
1 Reply
LisaT
by
Occasional Contributor II

Hi All: just an update to this.  I changed my code so that "hostfeatureLayer" used a featureLayer that was a direct reference to an SDE layer.  It is the original SDE layer that I published the hosted featurelayer from, so it has the exact same schema.  Just changing to that made it so that I can assign the attributes when I create the geometry of the feature.  I would VERY MUCH prefer to be able to publish this layer as Hosted and update the attributes.  Has anyone been successful in doing this?  Does the code structure need to change in some way?  

0 Kudos