Select to view content in your preferred language

featureLayer.applyEdits error after successful server operation

597
1
Jump to solution
12-21-2022 03:41 AM
ViktorSafar
Frequent Contributor

JS API v3.37 (used by the AGE I currently work with) and v3.42 (tried to use latest locally)

I have the following code

 

 

 

const updatedGraphic = new Graphic()
updatedGraphic.setGeometry(feature.geometry)
updatedGraphic.setAttributes(feature.attributes);

const featureLayer = new esriJS.FeatureLayer(featureLayerUrl);
featureLayer.applyEdits(null, [updatedGraphic], null,
  (adds, updates, deletes) => {
	resolve(updates);
  },
  err => {
	console.log(err);
	debugger
	reject(err);
  });

 

 

 

 

The call to the API succeeds. I can see in Fiddler the response is as expected and the payload contains the data for the returned array of [adds, updates, deletes]. The feature is also updated on the server.

The error I get originates in the handling JS:

 

 

 

TypeError: Cannot read properties of undefined (reading 'attributes')
    at Object._editHandler (init.js:2794:52)
    at Object.load (init.js:2730:514)
    at init.js:1006:78
    at e (init.js:105:393)
    at f (init.js:105:182)
    at resolve.callback (init.js:107:10)
    at e (init.js:106:96)
    at f (init.js:105:182)
    at resolve.callback (init.js:107:10)
    at e (init.js:106:96)

 

 

 

This is the updatedGraphic object (which is passed as an array to the applyEdits function)

 

{_constructed: true, geometry: {…}, symbol: undefined, attributes: {…}, _sanitizeNumericValue: ƒ, …}
attributes: {objectid: 14231, ftema: '0', fiskeribruk_type: '2', fiskeredskapskode: '10', objekt_id: null, …}
geometry: {rings: Array(1), _ring: 0, spatialReference: {…}}
infoTemplate: undefined
symbol: undefined
_computedAttributes: null
_computedGeomVersion: null
_computedVersion: null
_constructed: true
_geomVersion: 2
_sanitizeNumericValue: ƒ ()
[[Prototype]]: Object

 

 

I have basically the same code to send adds and that works fine 

 

 

 

const newGraphic = new Graphic()
newGraphic.setGeometry(feature.geometry)
newGraphic.setAttributes(feature.attributes);

const featureLayer = new esriJS.FeatureLayer(featureLayerUrl);
featureLayer.applyEdits([newGraphic], null, null,
  (adds, updates, deletes) => {
	resolve(adds);
  },
  err => {
	console.log(err);
	debugger
	reject(err);
  });

 

 

 

 

0 Kudos
1 Solution

Accepted Solutions
ViktorSafar
Frequent Contributor

Thanks to @JoelBennett  who pointed out that the layer needs to be loaded in order for the applyEdits to work properly https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-applyedits-ignores-3...

View solution in original post

0 Kudos
1 Reply
ViktorSafar
Frequent Contributor

Thanks to @JoelBennett  who pointed out that the layer needs to be loaded in order for the applyEdits to work properly https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-applyedits-ignores-3...

0 Kudos