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

6222
22
Jump to solution
05-22-2015 02:15 PM
ChrisSergent
Regular Contributor III

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
22 Replies
KyleMorgan
New Contributor III

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.

ChrisSergent
Regular Contributor III

Tried it out. No luck so far. Going to try again in the morning.

0 Kudos
ChrisSergent
Regular Contributor III

That's what ended up working for me by typing the following:  attributes.objectId = parseInt(attributes.objectId, 10);

Here is my commit on github where I updated my code is anyone needs it as a reference: csergent45/streetSigns at a59d005160c3a16346b8b4ad3fdb445d287d1b40 · GitHub

0 Kudos