Select to view content in your preferred language

Type Coercion failed: cannot convert Object@ee7f749 to com.esri.ags.Graphic

1676
7
11-07-2011 08:07 AM
RoyceSimpson
Frequent Contributor
Hello All,
I've got a stand-alone table published as a "feature layer" in a feature service that I'd like to be able to add/update/delete records.  What is the best way to do this?  Right now I create the featurelayer, then create a "map" object, add the feature layer to it and then do what I need to do.
However, recently I've been getting the below exception and not able to pin down why it's happening.  My guess is Object@ee7f749 is a record in the featurelayer, but since that object isn't a feature but a record (without geometry), things are getting messed up.

I am running this against 10.1 b1 service with Flex/AGS API 2.4. 

TypeError: Error #1034: Type Coercion failed: cannot convert Object@ee7f749 to com.esri.ags.Graphic.
 at com.esri.ags.layers::FeatureLayer/http://www.esri.com/2008/ags/internal::editHandler()
 at mx.rpc::AsyncResponder/result()
 at com.esri.ags.tasks::FeatureLayerTask/handleApplyEdits()
 at Function/http://adobe.com/AS3/2006/builtin::call()
Tags (2)
0 Kudos
7 Replies
RoyceSimpson
Frequent Contributor
UPDATE:  Darn.  Even though I had to make the below change, the original error is still present. 

Wow, that took a lot of time to debug.

Answer:  When doing updates to standalone table as in "myFL.applyEdits([], updatedRecords, [], new AsyncResponder(onUpdateResults, applyEditsFault));"

The updatedRecords array of attributes JSON objects at AGS version 10 needed to have ObjectID written like:  "objectId".
At version 10.1 b1 it needs to be written like "OBJECTID".

As in:

[{
"attributes":
{
"OBJECTID":677,
"fieldA":"0",
"fieldB":"1"
}
}
]

Fun times.
0 Kudos
RoyceSimpson
Frequent Contributor
I'm still having this issue and not sure how to proceed debugging it.  Here is some more detail on what triggers the above exception:

I create an object as follows.  This only has attributes since the feature layer that is getting the new record is a stand alone table.
_accountObject=
     {
      "attributes":
      {
       "OBJECTID":null,
       "LASTNAME":txtLastName.text,
       "FIRSTNAME":txtFirstName.text,
       "EMAILADDRESS":txtEmailAddress.text,
       "PHONENUMBER":txtPhoneNumber.text,
       "CREATIONDATE": new Date().toString(),
       "LASTUPDATE": new Date().toString()
      }
     } 


Then invoke the "applyedits" method against the _accountTable stand alone table FeatureLayer with the above object.

_accountTable.applyEdits([_accountObject], [], [], new AsyncResponder(applyEditsResults, applyEditsFault));


The exception noted in the OP is what comes next.  Neither applyEditsResults or applyEditsFault get invoked.

TypeError: Error #1034: Type Coercion failed: cannot convert Object@ee7f749 to com.esri.ags.Graphic.
 at com.esri.ags.layers::FeatureLayer/http://www.esri.com/2008/ags/internal::editHandler()
 at mx.rpc::AsyncResponder/result()
 at com.esri.ags.tasks::FeatureLayerTask/handleApplyEdits()
 at Function/http://adobe.com/AS3/2006/builtin::call()


I've verified that the object referenced in the exception is "_accountObject".
So, I'm not sure why the exception is happening since the feature layer object represents a table and not feature class... Why FeatureLayer.as is trying to convert it to a graphic is escaping me.

Once again, it needs to be noted that I am using the Flex/AGS 2.4 API against 10.1 b2 AGS installation.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Royce,

   I Believe you need to submit a graphic to the applyedits no matter what as in this sample:

http://help.arcgis.com/en/webapi/flex/samples/index.html#/Editing_a_related_table/01nq00000020000000...
0 Kudos
RoyceSimpson
Frequent Contributor
Royce,

   I Believe you need to submit a graphic to the applyedits no matter what as in this sample:

http://help.arcgis.com/en/webapi/flex/samples/index.html#/Editing_a_related_table/01nq00000020000000...


Thanks Robert but I think it only needs to be a graphic if the layer you are editing is a feature class.  If the layer is a stand alone table, you can just pass the attributes as my code snippet shows. 

The documentation for FeatureLayer within the Flex/AGS API pages states, "The feature layer can be used to display features from one single layer of either a Feature Service or a Map Service. The layer can be either a (spatial) layer or a (non-spatial) table. The features in a FeatureLayer can be edited if it is based on a Feature Service. "

The applyedits method documentation does not state one way or another if the edits can only be to graphical features.

Also, this according the the AGS REST API feature service documentation:  "Records to be added to a table should not include the geometry."

Lastly, I can go to the web interface for the stand alone table within the feature service and add a "null" record from within the "applyedits/adds" operation... as in [{}]... and the record is added to the table just fine.  (see the attached png image).
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Royce,

   So have you tried to submit a graphic that has a null for geometry as in the sample (which by the way is editing a related Flat table).

            private function voteImage_clickHandler(event:MouseEvent):void
            {
                const voteRecordAttributes:Object = {
                        sf_311_serviceoid: selectedGraphic.attributes.objectid,
                        datetime: new Date().getTime(),
                        agree_with_incident: 1
                    };
                const voteRecord:Graphic = new Graphic(null, null, voteRecordAttributes);

                const incidentVoteTable:FeatureLayer = new FeatureLayer("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/1");
                incidentVoteTable.addEventListener(FeatureLayerEvent.EDITS_COMPLETE, incidentVoteTable_editsCompleteHandler);
                incidentVoteTable.applyEdits([ voteRecord ], null, null);
            }
0 Kudos
RoyceSimpson
Frequent Contributor
Royce,

   So have you tried to submit a graphic that has a null for geometry as in the sample (which by the way is editing a related Flat table).

            private function voteImage_clickHandler(event:MouseEvent):void
            {
                const voteRecordAttributes:Object = {
                        sf_311_serviceoid: selectedGraphic.attributes.objectid,
                        datetime: new Date().getTime(),
                        agree_with_incident: 1
                    };
                const voteRecord:Graphic = new Graphic(null, null, voteRecordAttributes);

                const incidentVoteTable:FeatureLayer = new FeatureLayer("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/1");
                incidentVoteTable.addEventListener(FeatureLayerEvent.EDITS_COMPLETE, incidentVoteTable_editsCompleteHandler);
                incidentVoteTable.applyEdits([ voteRecord ], null, null);
            }


I hadn't but just did and damned if it didn't work.  The reason I paid little attention to the sample is because I have another app that is doing it by just supplying the attributes as my previous post shows and it works just fine...  So I was stuck on the "it can't be my code" delusion.  In any case, your suggestion works, even though creating a "graphic" without any geometry is strange.  It's good enough for me.

Thanks much.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Royce,

   Actually I'm not sure why it would have ever worked without you sending a graphic as that is what the applyEdits is expecting (an Array of Graphics). Glad you got it working.
0 Kudos