FeatureLayer using FeatureCollection option ... query exception thrown

5427
4
Jump to solution
07-31-2013 09:50 AM
DianaBenedict
Occasional Contributor III
Background:
- ArcGIS Server 10.1 sp1 using JS API 3.5
- Web Editing Application editing SDE Data (works fine .. for the most part)

Issue:
I have hit a roadblock when attempting to use a FeatureCollection to hold potential related attribute records.

Workflow:
Utilize the FeatureLayer with FeatureCollection option to create a temporary table to hold additional attributes for an edit featureLayer.  I have a feature class that I have served as a featureService in ArcGIS server. We would like to provide the option to allow the user to specify additional attributes stored in a seperate attribute table (no relationship class just simple PK-FK relationship). I have successfully used the ESRI AttributeInspector to manage the attribute tables and related tables. However, I was not fond of having an "Add" button to create force the users to create a new record in the related attribute table. I would prefer the record to be preloaded on the page and allow the user to Save the new record or changes back to the table.  Because of the way the AttributeInspector dijit works you MUST have records selected in order for them to be displayed in the UI.  This is simple to do with FeatureLayers that use a REST URL however, it appears that I am running into a roadblock when selecting records from a FeatureLayer with the FeatureCollection option.

Exception/Error:
I am getting the following exception thrown when attempting to retrieve/select the newly created record from the FeatureCollection.
"FeatureLayer::selectFeatures - query contains one or more unsupported parameters"

Supporting  Research Information:
ESRI Documentation: https://developers.arcgis.com/en/javascript/jsapi/featurelayer.html#featurelayer2
Does not support queries that need to be performed on the server, e.g. queries with a where clause or non-extent based spatial queries.


Forum Post: Clone a Server-based FeatureLayer to a local one?
http://forums.arcgis.com/threads/14665-clone-a-server-based-featurelayer-to-a-local-one
Dasa Paddock indicated that I should be able to use a query with objectIds paramater set.

1.) You can select features in a FeatureLayer that's using a FeatureCollection using an Extent geometry, objectIds or timeExtent.

2.) The AttributeInspector should work with a FeatureLayer that's using a FeatureCollection.

Dasa Paddock
Esri Flex Team


Forum Post: AttributeInspector requires a FeatureLayer when using graphics?
http://forums.arcgis.com/threads/65604-AttributeInspector-requires-a-FeatureLayer-when-using-graphic...
You could create a feature collection based feature layer and use that with the AttributeInspector widget.
.. Kelly Hutchins (ESRI)


What does this all mean:
Exactly .. I am at a standstill. Initially, I had incorrectly used a where paramater with the query for the FeatureCollection but quickly remedied that. I am still getting the same error. Since this is a table with no geometry I do not have the option to select using a geometry paramater.  Any ideas?

Below is the code that I use to test this use case:

    //NEW code to test the creation of the FeatureCollection FeatureLayer    //I have tried diferent variations of this code and have simplified it down to this     var fieldsArray = [{ "name": "OBJECTID", "type": "esriFieldTypeOID", "alias": "OBJECTID" },       { "name": "GAZ_ID", "type": "esriFieldTypeInteger", "alias": "GAZ_ID" },       { "name": "GAZ_FEATUREHISTORY", "type": "esriFieldTypeString", "alias": "GAZ_FEATUREHISTORY", "length": 1073741822 },       { "name": "GAZ_FEATUREDESCRIPTION", "type": "esriFieldTypeString", "alias": "GAZ_FEATUREDESCRIPTION", "length": 1073741822}];     var layerDefinition = { "type": "Table", "fields": fieldsArray };     var featureCollection = { "layerDefinition": layerDefinition, featureSet: null };     _customFeatureLayer = new esri.layers.FeatureLayer(featureCollection, { "id": "myCustomClass", outFields: ["GAZ_ID", "GAZ_FEATUREHISTORY", "GAZ_FEATUREDESCRIPTION"] });     _customFeatureLayer.setEditable(true);     _map.addLayer(_customFeatureLayer);  //create the layerInfo to add to the attribute inspector var layerInfos = [{ 'featureLayer': _customFeatureLayer, 'fieldInfos': fieldInfos, 'isEditable': isTableEditable, 'showDeleteButton': false}]; var relTableAttInspector = new esri.dijit.AttributeInspector(           { 'layerInfos': layerInfos }, attributeDivId);  //at some point in the app prior to showing the attribut UI I attempt to create a new record in the FeatureCollection layer based on an existing attribute record from the FeatureLayer/table          _customFeatureLayer.applyEdits(results.selectionLayers[0].features, null, null, function (addResults) {           if (addResults[0].success) {             //var jsonObject = _customFeatureLayer.toJson();             //Now select the record so it shows up in the attribute UI             var query = new esri.tasks.Query();             query.returnGeometry = false;             query.objectIds = [addResults[0].objectId];             query.outFields = ["GAZ_ID", "GAZ_FEATUREHISTORY", "GAZ_FEATUREDESCRIPTION"];             _customFeatureLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW, function (features) {               helperOperations.hideProcessingDialog();               showAttributePane();             }, function (e) {               processError("Error: " + e.message);             });           } else {             helperOperations.hideProcessingDialog();             showAttributePane();           }         }, function (error) {           processError("Error: unable to insert a record into the custom FeatureLayer");         }); 
0 Kudos
1 Solution

Accepted Solutions
DianaBenedict
Occasional Contributor III
I am responding to this thread so that anyone else who encounters this issue is aware of the limitations of the software (intended or not).

It appears that this exception will continue to be thrown when creating a FeatureLayer with the FeatureCollection option if you do not spatially enable the Layer. So the example above that I have shown, creates a new esri FeatureLayer with no geometry since it is intended to be a related Table not Feature Class.  In order to get the functionality to work as intended, you must have geometry included in your layer definition and then you can query the records using the query.objectIds paramater.  Once I added a "fake" geometry and then used the applyEdits to add a new record (with null geometry) I was able to successfully retrieve the records of interest.

Well, the good new is that I have it working ... even if it means that I must insert null geometry. I am not sure if ESRI is aware of this limitation as it would be a functionality that not too many people really use (I guess).

View solution in original post

4 Replies
DianaBenedict
Occasional Contributor III
I am responding to this thread so that anyone else who encounters this issue is aware of the limitations of the software (intended or not).

It appears that this exception will continue to be thrown when creating a FeatureLayer with the FeatureCollection option if you do not spatially enable the Layer. So the example above that I have shown, creates a new esri FeatureLayer with no geometry since it is intended to be a related Table not Feature Class.  In order to get the functionality to work as intended, you must have geometry included in your layer definition and then you can query the records using the query.objectIds paramater.  Once I added a "fake" geometry and then used the applyEdits to add a new record (with null geometry) I was able to successfully retrieve the records of interest.

Well, the good new is that I have it working ... even if it means that I must insert null geometry. I am not sure if ESRI is aware of this limitation as it would be a functionality that not too many people really use (I guess).
ArjunDongre
Occasional Contributor

So this thread is really old - but maybe you can still help me out? I am getting the same error you did at v3.22.  I am creating a feature layer from a feature collection (so all the data is stored client side). My data is already spatial, and I define it as such when I instantiate the featurelayer ("esriGeometryPoint")., but I'm still getting the error. Would you happen to still have the code that you used to get this working? The only difference is that I am not needing to query on objectIds. I just want to query based on a mappoint and distance buffer, and no where statement.

thanks!

0 Kudos
ArjunDongre
Occasional Contributor

Also it seems that the queryObjectIDs is mandatory for it to work? This makes no sense to me. Basically I can grab single features from an on click event on the feature layer directly, however, what if <1 point are on top of each other? I want all the data. Hence, I was going to use the queryfeatures with a buffer with a map on click.  I don't know what my objectids are, and I don't actually care. Any ideas?

0 Kudos
DianaBenedict
Occasional Contributor III

Hi sorry for the late response, I only just now logged back in to my personal ESRI account and saw this thread. I no longer have access to the code since I do not work at that client - got a new gig. But if you want to share your code, I would be happy to look at it and see if I have any ideas on what might be going on.

Diana

0 Kudos