Why can't I apply edits on a featurelayer if i have edited attributes of my object?

1622
7
07-30-2013 12:51 PM
grahamcooke
Occasional Contributor
Hi,

I am still getting to grips with editing functionality on featurelayers so I hope someone can help:

I have a graphic created at runtime that has some attributes attached to it. I want to publish that graphic as a feature to a feature layer in the operational layers of my viewer. This works brilliantly.

The issue is that my users may not wish to publish the graphic to the database but still need to generate it and consequently it's attributes as it may be saved away as a file and recalled at a later time (siilar to how Robert Scheitlins eDraw widget does it!).

But if publish option is selected, I need them to add some further detail (like dates and a comment) which will then be used to filter the feature layer when selecting from it later. This needs to be added as an extra couple of attributes which then also need to be written to the feature class.

If I add extra attributes before I apply the edits and add the feature, it doesnt save at all. I get no exceptions and it looks as though it worked, but the data is not in the feature class. I have no idea why!

Here is my code that works fine:

private function publishWDADetail():void

                  {

                        //need to be able to add the values from the controls to the attributes of the graphic in order to save information that

                        //is searchable by date to the feature class!
                        //this works but doesnt have form attributes in it
                        //publish the selected graphic by creating it as a feature and applying it as an edit to the feature layer for published traces

                        publishingFeatureLayer = map.getLayer("Traces") as FeatureLayer;
                       publishingFeatureLayer.applyEdits([ publishedTraceGraphic ], null, null);


This code below should work (i think!) - but doesn't. When I use the variables window to explore the attributes of the graphic object I can see the attributes have been added as expected!
                        addAttributesFromControls()

                        publishingFeatureLayer = map.getLayer("Traces") as FeatureLayer;

                        PublishingFeatureLayer.applyEdits([ publishedTraceGraphic ], null, null);

//here is the code I am using to add extra attributes to the publishedTraceGraphic Graphic object from my attribute widget.
                   private function addAttributesFromControls():void

                  {

                        publishedTraceGraphic.attributes["USER_TAG"] = txtUserTag.text; 
                        publishedTraceGraphic.attributes["COMMENT"] = txtComment.text;
                        publishedTraceGraphic.attributes["TRAINING_AREA_NAME"] = ViewerContainer.getInstance().mapManager.trainingAreaName;
                        publishedTraceGraphic.attributes["RANGE_STATUS_ID"] = "4";
                        publishedTraceGraphic.attributes["FIRING_START_DATE"] = getDateTime("DateFrom").toString();
                        publishedTraceGraphic.attributes["FIRING_END_DATE"] = getDateTime("DateTo").toString();
                        publishedTraceGraphic.refresh();

                       

                  }

                  
                  
All ideas welcome! This one is keeping me up at night!
Tags (2)
0 Kudos
7 Replies
DasaPaddock
Esri Regular Contributor
Have you checked the HTTP traffic using a tool like Fiddler or Charles Proxy?

You could remove the extra attributes before calling applyEdits() using:

    delete publishedTraceGraphic.attributes["USER_TAG"];
0 Kudos
grahamcooke
Occasional Contributor
Hi Dasa,

Thanks for replying, sorry for my late reply I was out of office yesterday.

I have checked with fiddler and the output is the same in both instances with the exception that the attributes come in a different order in the second case which is the one I am trying to get working. Is there anything particularly I should be looking out for in the fiddler results?

I dont want to delete the extra attributes, I really need them to be saved to the database as the dates are what I will filter results on after the features have been saved.

Any further ideas on this one would be really appreciated as it's a show stopper for my customer. Without this ability to effectively publish graphics they have created, the system is missing on of it's key requirements.

thanks,
0 Kudos
DasaPaddock
Esri Regular Contributor
I would use look for any errors in the HTTP responses.

I thought the extra attributes were not in the feature class. If you trying to set date fields, they should be in the form of number of milliseconds since 1970 (myDate.time). It looks like you're trying to send a date string.
0 Kudos
grahamcooke
Occasional Contributor
Hi Dasa,

Yes the attributes are in the feature clas, they are just not attributes of the graphic I am publishing to the feature class. Those attributes need to be added AFTER the user generates the graphic and chooses to publish it.

In the attached screen shot, the blue graphic shown has been generated from the weapon danger area widget. When the user selects that and hits the publish button, the second widget to publish the trace appears and hitting save on that should add the values from the form to the attributes of the graphic snd publish it using the code I previously posted (which I took from the edit without editor sample).

Hope that makes more sense? I also attach output from fiddler. Interesting point about the dates, but I did wonder if the dates were wrong and tried the same code, just without adding the dates to the attributes and it still didn't work??

Bit confused by the milliseconds since 1970 format you allude to?

thanks
0 Kudos
DasaPaddock
Esri Regular Contributor
Have you looked at the HTTP response in Fiddler? Your attachment was only the HTTP request.

You can get the number of milliseconds since 1970 using the time property on Date:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Date.html#time
0 Kudos
grahamcooke
Occasional Contributor
Hi Dasa, Thanks for your patience - I am getting closer!

Turns out there is an error in the response and that error is "the geometry is not z-aware". I went to the service properties and clicked the apply default z value in the feature access properties but still get the error!
0 Kudos
grahamcooke
Occasional Contributor
Hi Dasa,

I have cracked it. You were spot on with the dates. I have amended my routine that returns the date and removed the tostring() in the function that adds the date attributes. All working great except one small thing which is the hours I enter in my number stepped are being interpreted as a time one hour earlier! So I ever 4am to 5pm and the times are saved away as 3am to 4pm. I should be able to sort that tomorrow though.

Thanks so much for your assistance.
0 Kudos