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.