My application will create new feature points, but will not update existing points. Is there different syntax besides the applyEdits to perform an update? I have debugged and the attributes are there when I start. They just don't take, which is why I thought my syntax may be wrong.
Here is a block of code that I am trying to use for one of the updates:
// get sign attributes from form and submit var updateSigns = function () { // alert(domClass.contains("attributesSignModal", "in")); var attributes = { // TODO: not sure if this is needed //requestreceived: null }; var currentDate = new Date(); // current date is defined but never used. var graphic; graphic = new Graphic(app.currentGeometry); query("#attributesSignModal input, #attributesSignModal select, #attributesSignModal textarea").forEach(function (formInput) { attributes[formInput.name] = formInput.value; }); // Form validation - ensures that the values for the data are here if left blank if ((attributes.installed === undefined) || (attributes.installed === "")) { attributes.installed = null; } if ((attributes.signId === undefined) || (attributes.signId === "")) { attributes.signId = null; } if ((attributes.supportId === undefined) || (attributes.supportId === "")) { attributes.supportId = null; } graphic.setAttributes(attributes); stopCaptureRequest(); console.log(attributes); app.signLayer.applyEdits(null, [graphic], null).then(function (response) { console.log(response); app.signLayer.refresh(); }); };
and here is an addSign that does work:
// get sign attributes from form and submit var addSigns = function () { // alert(domClass.contains("attributesSignModal", "in")); var attributes = { // TODO: not sure if this is needed //requestreceived: null }; var currentDate = new Date(); // current date is defined but never used. var graphic; graphic = new Graphic(app.currentGeometry); query("#attributesSignModal input, #attributesSignModal select, #attributesSignModal textarea").forEach(function(formInput) { attributes[formInput.name] = formInput.value; }); // Form validation - ensures that the values for the data are here if left blank if ((attributes.installed === undefined)|| (attributes.installed === "")) { attributes.installed = null; } if ((attributes.signId === undefined) || (attributes.signId === "")) { attributes.signId = null; } if ((attributes.supportId === undefined) || (attributes.supportId === "")) { attributes.supportId = null; } graphic.setAttributes(attributes); stopCaptureRequest(); console.log(attributes); app.signLayer.applyEdits([graphic], null, null).then(function (response) { console.log(response); app.signLayer.refresh(); }); };
and finally, here is my latest github commit:
csergent45/streetSigns at 787b3ed59a446ca1cfcb8229d696b3445c4dda59 · GitHub
Solved! Go to Solution.
Hey Chris,
Make sure your form is submitting the correct "type" during your POST operation. Number fields and ObjectIDs can't be passed as strings (wrapped in ' or "). You can use parseInt(<field>)/parseFloat(<field>) on the appropriate text fields before applying the API applyEdits() call.
Chris,
the applyEdits method take an arrays for adds, updates, and deletes. Depending on which operation you are attempting to do will determine which position you need to have that array in.
Notice for updates the array has to be in the second position.
applyEdits(null, [your updates], null, callback, errback)
Right and that's the way I have it in my first block of code.
Chris,
Sorry I did not see that. Try adding an error callback function so that you can see what the issue is. Right not you only have a result call back.
Robert,
I'll have to look into that hopefully at home if I can this weekend. Our area looks like it's shutting down right now.
I was getting an error on this statement though, couldn't figure out why: app.attributesSignModal.modal("hide");
Chris,
Are you sure that there is a modal function on this app.attributesSignModal object?
Yes, modal is a function. There is a file modal.js and I have use it on other elements to hide or show.
I did take out the hide line and then received an error, unable to completed function, so I believe it's something before I hide the form.
The code never makes it to the second line of code shown here:
app.signLayer.applyEdits([graphic], null, null).then(function (response) { console.log(response); app.signLayer.refresh(); });
I am not sure what to write for a callback. Do you have an example?
You may also want to check that the OBJECTID for the feature you're trying to update is included in the attributes. I know that tripped me up before.
https://developers.arcgis.com/javascript/jsapi/featurelayer-amd.html#applyedits