Select to view content in your preferred language

Why won't apply edits update, but adding a new point will for Features?

6805
22
Jump to solution
05-22-2015 02:15 PM
ChrisSergent
Deactivated User

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

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
KyleMorgan
Deactivated User

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.

View solution in original post

22 Replies
RobertScheitlin__GISP
MVP Emeritus

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.

applyEdits(adds?, updates?, deletes?, callback?, errback?)

Notice for updates the array has to be in the second position.

applyEdits(null, [your updates], null, callback, errback)

ChrisSergent
Deactivated User

Right and that's the way I have it in my first block of code.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

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.

ChrisSergent
Deactivated User

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");

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Chris,

   Are you sure that there is a modal function on this app.attributesSignModal object?

0 Kudos
ChrisSergent
Deactivated User

Yes, modal is a function. There is a file modal.js and I have use it on other elements to hide or show.

0 Kudos
ChrisSergent
Deactivated User

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();
           
        });
0 Kudos
ChrisSergent
Deactivated User

I am not sure what to write for a callback. Do you have an example?

0 Kudos
BethManghi
Regular Contributor

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

0 Kudos