Select to view content in your preferred language

Record Count of a Feature Layer

3339
11
Jump to solution
12-20-2013 06:20 AM
ionarawilson1
Deactivated User
I am filtering a non-spatial feature service cast a feature layer. How can I get the record count after the search is complete? I know I can use  the length of feature layer graphic provider if the feature layer is an actual feature layer. But how can I the number of records for a non-spatial table (named yourTable)? How can I modify the last line of the code snippet in this case?
Thank you so much in advance
Thanks

private function doSearch():void    {          myAttributeTable.featureLayer = myFeatureLayer         var defexpr:String =  searchattribute +  eqsymbol +  "'"  +  qText.text  + "'";      yourTable.definitionExpression = defexpr     myAttributeTable.featureLayer = yourTable     Alert.show(defexpr)     totalGraphicsShown = "Total records shown: " + (yourTable.graphicProvider as ArrayCollection).length 
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ionarawilson1
Deactivated User
This is what worked for  me:

var defexpr6:String =  "DateComplete >= " +   "'"  +  date1.text  + "'" + " AND DateComplete <= " + "'"  +  date2.text  + "'";      //    var defexpr:String =  searchattribute +  eqsymbol +  "'"  +  qText.text  + zerotime + "'";      yourTable.definitionExpression = defexpr6      myAttributeTable.featureLayer = yourTable      myAttributeTable.visible = true;      Alert.show(defexpr6)      query.where = defexpr6;      query.objectIds=[];      query.returnGeometry = false;      queryTask.executeForIds(query);     var objectIdsArray = [];    function  executeForIdsOnResult(event:QueryEvent):void         {          queryTask.removeEventListener(QueryEvent.EXECUTE_FOR_IDS_COMPLETE,executeForIdsOnResult);     objectIdsArray = event.objectIds;     numberofrecords.text = objectIdsArray.length.toString();         } 


And the mxml

 <esri:QueryTask id="queryTask"       url="http://tfsgis-iisd01:6080/arcgis/rest/services/SARS_WILSON/RELATED_TABLES/FeatureServer/1"       executeForIdsComplete="executeForIdsOnResult(event)"       useAMF="false"              />   <esri:Query id="query"      outFields=""       returnGeometry="false"      />           <mx:Text width="65" id="numberofrecords"         text="test"/>

View solution in original post

0 Kudos
11 Replies
RobertScheitlin__GISP
MVP Emeritus
Ionara,

   The only way I know to make it work is to use the queryCount method to perform a query using the same SQL expression that you are setting for the defenitionExpression.

0 Kudos
ionarawilson1
Deactivated User
Hi Robert,

Can you please post a code snippet of an example of a querycount just for me to have an idea how to use it? thank you!!!
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Ionara,

   I don't have a code example. It is just like any query you would do against a layer. Look at the documentation link I posted and you will see that it is identical to other queries.
0 Kudos
ionarawilson1
Deactivated User
Ok, I will try, Thank you!!!
0 Kudos
ionarawilson1
Deactivated User
Robert,

I think I might be in the right track. Can you please tell me how I get the count of features and what url I put in the query task since I am query a feature layer? Do I even need a query task since I am not executing it? Thank you!

 var query:Query = new Query();
    query.where = defexpr
    query.returnGeometry = false;
    yourTable.queryCount(query, new AsyncResponder(onResult, onFault));
    
    
    function onResult(featureSet:FeatureSet,token:Object = null):void
    {
     
     
     
     
    }
    
    function onFault(info:Object, token:Object = null):void
    {
     
    }
    


  <esri:QueryTask id="queryTask"
      
      url="http://tfsgis-iisd01:6080/arcgis/rest/services/SARS_WILSON/RELATED_TABLES/MapServer/1"/>
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Ionara,

   There is no need for a QueryTask and thus no need for a URL.
0 Kudos
ionarawilson1
Deactivated User
Good, can you tell me if I am in the right track and how to get the count value?  Would I just add
featureSet.features.length

to the result function?

Thank you!
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Ionara,

   Try this...

function onResult(count:Number, token:Object):void
                {
                    trace(count);
                }
0 Kudos
ionarawilson1
Deactivated User
Thank you Robert. I will try this when I go back to the office on the 6th.
0 Kudos