Update attributes with applyEdits() [NEED HELP]

9764
16
Jump to solution
06-13-2012 12:50 PM
SachaTousignant
New Contributor III
Hello everyone,

I'm currently trying to update a feature layer without attribute inspector (gave up with the attribute inspector / editor since I had no control over it for the interface).

My first problem is the following :
I have an error with my applyEdits : Invalid graphic features, Invalid parameters
And I just found out why, it's because one of my field is a date with a format like 2012/06/13 04:00:00 UTC and I was trying to update it with a 2010-01-01 format.

My second problem is the following :
So without the date, the applyEdits goes into the onResult but, no changes have been made to the feature layer and it doesn't even trigger the editComplete nor editsStarting events from the feature layer.

Here's the code :
feature.attributes={OBJECTID:gr.attributes.OBJECTID,      RESP_PERQ:strRespPerq,      RESULT:strResultatF,      NBR_PLANTS:strNbrPlant,      RAISON:strRaison,      CONFUSION:strConfusion};  featureLayerFiche.applyEdits(null, [feature], null, new AsyncResponder(onResult, onFault));              function onResult():void     {      Alert.show("ONRESULT");     }          function onFault(info:Object, token:Object = null):void     {      Alert.show(info.toString());     }  // LOAD OF CODE ... // <esri:FeatureLayer id="featureLayerFiche"         mode="snapshot"         outFields="[OBJECTID, IDFICHE, NM_MUN, UNITE, DISTRICT, DATEFICHE, RESP_PERQ, DATE_PERQ, RESULT, NBR_PLANTS, RAISON, CONFUSION]"         selectionComplete="myFeatureLayer_selectionCompleteHandler(event)"         editsComplete="featureLayerFiche_EditsCompleteHandler"         editsStarting="featureLayerFiche_EditsStartingHandler"         fault="featureLayerFiche_FaultHandler"         disableClientCaching="true"         url="http://myserver123/ArcGIS/rest/services/geocisaille/FeatureServer/1"/>  // LOAD OF CODE ... // 


So I'm just wondering why it doesnt trigger my events if it went into the onResult function.

*Also, I tried to place the [feature] in the delete array and it works, so I can delete feature with no problem.*

Any help would be greatly appreciated, since there's not alot of docs about it.
Lmk if you need more informations.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
SachaTousignant
New Contributor III
This problem is now solved! TY alot Dasa Paddock for your help!

With Fiddler2, I saw that my objectID in the result was at random, a number between -10000 and 10000.
It happened because I had : "OBJECTID" : "24" instead of : "OBJECTID" : 24

I didn't notice my OBJECTID was in a string due to graphicVariable.attributes.OBJECTID which is a string.

Thx again everyone!

View solution in original post

0 Kudos
16 Replies
CaseyBentz
Occasional Contributor II
Just a wild guess here.  I would assume that you using the AsyncResponder overrides the edits complete event for the feature layer. 

Have you tried just doing featureLayerFiche.applyEdits(null, [feature], null);  That is how I do it outside of the attribute inspector, and it works everytime.

Hello everyone,

I'm currently trying to update a feature layer without attribute inspector (gave up with the attribute inspector / editor since I had no control over it for the interface).

My first problem is the following :
I have an error with my applyEdits : Invalid graphic features, Invalid parameters
And I just found out why, it's because one of my field is a date with a format like 2012/06/13 04:00:00 UTC and I was trying to update it with a 2010-01-01 format.

My second problem is the following :
So without the date, the applyEdits goes into the onResult but, no changes have been made to the feature layer and it doesn't even trigger the editComplete nor editsStarting events from the feature layer.

Here's the code :
feature.attributes={OBJECTID:gr.attributes.OBJECTID,
                    RESP_PERQ:strRespPerq,
                    RESULT:strResultatF,
                    NBR_PLANTS:strNbrPlant,
                    RAISON:strRaison,
                    CONFUSION:strConfusion};

featureLayerFiche.applyEdits(null, [feature], null, new AsyncResponder(onResult, onFault));
                                
                function onResult():void
                {
                    Alert.show("ONRESULT");
                }
                
                function onFault(info:Object, token:Object = null):void
                {
                    Alert.show(info.toString());
                }

// LOAD OF CODE
...
//
<esri:FeatureLayer id="featureLayerFiche"
                       mode="snapshot"
                       outFields="[OBJECTID, IDFICHE, NM_MUN, UNITE, DISTRICT, DATEFICHE, RESP_PERQ, DATE_PERQ, RESULT, NBR_PLANTS, RAISON, CONFUSION]"
                       selectionComplete="myFeatureLayer_selectionCompleteHandler(event)"
                       editsComplete="featureLayerFiche_EditsCompleteHandler"
                       editsStarting="featureLayerFiche_EditsStartingHandler"
                       fault="featureLayerFiche_FaultHandler"
                       disableClientCaching="true"
                       url="http://myserver123/ArcGIS/rest/services/geocisaille/FeatureServer/1"/>

// LOAD OF CODE
...
//



So I'm just wondering why it doesnt trigger my events if it went into the onResult function.

*Also, I tried to place the [feature] in the delete array and it works, so I can delete feature with no problem.*

Any help would be greatly appreciated, since there's not alot of docs about it.
Lmk if you need more informations.
0 Kudos
SachaTousignant
New Contributor III
Just a wild guess here.  I would assume that you using the AsyncResponder overrides the edits complete event for the feature layer. 

Have you tried just doing featureLayerFiche.applyEdits(null, [feature], null);  That is how I do it outside of the attribute inspector, and it works everytime.


EDIT :: OKAY, I found out why my editsComplete + editsStarting events wouldn't trigger, I changed my code from this :
editsComplete="featureLayerFiche_EditsCompleteHandler"
editsStarting="featureLayerFiche_EditsStartingHandler"

to this :

editsComplete="featureLayerFiche_EditsCompleteHandler(event)"
editsStarting="featureLayerFiche_EditsStartingHandler(event)"

So now I know that my edit is started and completes itself but my problem still remain, my feature aren't getting really updated.



Ty for your reply but unfortunetly, it doesn't work even without the AsyncResponder.
I tried some other stuff and by using featureLayerFiche.applyEdits(null, null, [feature]); I can delete the feature but it doesn't even trigger the editsStarting neither the editsComplete.

DOCS :
com.esri.ags.layers.FeatureLayer.editsStarting
Dispatched when applyEdits is called, but before the edits request is sent to the server. This event is cancelable by calling event.preventDefault() which will stop the request from being sent.

com.esri.ags.layers.FeatureLayer.editsComplete
Dispatched when an applyEdits operation successfully completes.


It's well written, when applyEdits is called but in my case it doesn't for some unknown reason.

I'm also wondering why the delete is working but the update isn't, even tho now both of them successfully pass thru the applyEdits().
0 Kudos
SachaTousignant
New Contributor III
Btw, I tried to put the AsyncResponder with the events of editing and they all trigger.


Also, I'm thinking that my updating problem is coming from the attributes. I'm trying to change only a few of them but maybe the array needs all fields? Or maybe in a certain order? I'm still working on that.
0 Kudos
DasaPaddock
Esri Regular Contributor
Sacha,

You can change the UI of the components by customizing their skins. See:
http://resources.arcgis.com/en/help/flex-api/concepts/index.html#/Styling_and_skinning_overview/017p...

You can update a date field by making the attribute value be a Date or a Number.

You should be getting the events whether you use a responder or not. Are you testing with a debug Flash Player? If not, you won't see the any runtime errors.

The onResult signature should be like:
function myResultFunction(result:Object, token:Object = null):void

You can also type the result as a FeatureEditResults class. You can check each FeatureEditResult to see if "success" is true or not. You can also use a tool like HttpFox or Charles Proxy to watch the network traffic and see what the response from the server is.

This sample may be helpful:
http://resources.arcgis.com/en/help/flex-api/samples/index.html#/Edit_without_Editor/01nq00000043000...
0 Kudos
SachaTousignant
New Contributor III
Sacha,

You can change the UI of the components by customizing their skins. See:
http://resources.arcgis.com/en/help/flex-api/concepts/index.html#/Styling_and_skinning_overview/017p...

You can update a date field by making the attribute value be a Date or a Number.

You should be getting the events whether you use a responder or not. Are you testing with a debug Flash Player? If not, you won't see the any runtime errors.

The onResult signature should be like:
function myResultFunction(result:Object, token:Object = null):void

You can also type the result as a FeatureEditResults class. You can check each FeatureEditResult to see if "success" is true or not. You can also use a tool like HttpFox or Charles Proxy to watch the network traffic and see what the response from the server is.


This sample may be helpful:
http://resources.arcgis.com/en/help/flex-api/samples/index.html#/Edit_without_Editor/01nq00000043000...


This have been really useful, I now know that the update operation fails due to success = false and the error message is : Error: Update for the object was not attempted. Object may not exist.

To be quite honest, I have no idea where to go from that error. I don't get why it's not even attempting to update it, while the object clearly exists.
0 Kudos
DasaPaddock
Esri Regular Contributor
I'd double-check the request to make sure the right object id is being sent.
0 Kudos
SachaTousignant
New Contributor III
I'd double-check the request to make sure the right object id is being sent.


I don't think that's my problem since :

1st : I can delete features.
2nd : The error message clearly says that he's not EVEN attempting to update it.


I find this really sad since I don't see anyone who posted this error before so I'm kinda stuck.

Even tho, I checked and the right OBJECTID is sent + I checked the database to see if it was there. And it's all ok.
Well this is the way I proceed :

feature.attributes={OBJECTID:gr.attributes.OBJECTID, NBR_PLANTS:strNbrPlant};
featureLayerFiche.applyEdits(null, [feature], null, new AsyncResponder(onResult, onFault));
0 Kudos
DasaPaddock
Esri Regular Contributor
Does it work with the Editor component? See:
http://resources.arcgis.com/en/help/flex-api/samples/index.html#/Default_Editor/01nq0000001r000000/

If yes, what is the difference in the HTTP requests?
0 Kudos
SachaTousignant
New Contributor III
Does it work with the Editor component? See:
http://resources.arcgis.com/en/help/flex-api/samples/index.html#/Default_Editor/01nq0000001r000000/

If yes, what is the difference in the HTTP requests?


Yes, it works with editor, tho I gave up on it since I had no control over the interface.
I don't really know how to check the HTTP requests, is it with HTTPFox or Charle proxy like you said?
0 Kudos