Select to view content in your preferred language

Using Flex query a layer by field other than display field.

1527
10
07-06-2010 09:57 AM
PaulLang
Deactivated User
ArcGIS Server 9.3.1 Flex 1.3
How can you query fields other than the Display Field:
Tags (2)
0 Kudos
10 Replies
Drew
by
Frequent Contributor
Paul,

See this sample to query your features table.
http://resources.esri.com/help/9.3/arcgisserver/apis/flex/samples/index.html?sample=QueryTaskNoMap

EDIT: Then add the "where" clause as outlined in the docs.
http://resources.esri.com/help/9.3/arcgisserver/apis/flex/apiref/com/esri/ags/tasks/Query.html


You can view all the ESRI Flex 1.3 samples here if you wish to explore further.
http://resources.esri.com/help/9.3/arcgisserver/apis/flex/samples/index.html
0 Kudos
SreeS
by
Emerging Contributor
You can query any field that you want. It need not be the Primary display field.

It depends on what expression you are feeding your "query.where".
0 Kudos
PaulLang
Deactivated User
private function doQuery():void
        {
         queryTask.execute(query, new AsyncResponder( onResult, onFault));
            function onResult(featureSet:FeatureSet, token:Object = null):void
            {
             var unionExtent:Extent;
                var myFirstGraphic:Graphic = featureSet.features[0];
                //dataApp.visible = true;
                unionExtent = Polygon(myFirstGraphic.geometry).extent;
                MainMap.extent = unionExtent;
                myFirstGraphic.toolTip = "AKPAR: " + myFirstGraphic.attributes.AKPAR + "\n" + "Current Owner: " + myFirstGraphic.attributes.CURR_NAME1 + "\n" + "Current Owner: " + myFirstGraphic.attributes.CURR_NAME2 + "\n" + "Address: " + myFirstGraphic.attributes.CURR_ADDR1  ;
             dpFlat.push(dataGrid1.dataProvider.toString());
            
            }
            function onFault(info:Object, token:Object = null):void
            {
                Alert.show(info.toString());
            }
        }


<esri:QueryTask id="queryTask" url="http://egov3/ArcGIS/rest/services/Testing/Dynamic/MapServer/0/" />
     <esri:Query id="query" text="{qText.text}" returnGeometry="true">
         <esri:outFields>
          <mx:String>DISTHIGH</mx:String>
             <mx:String>DISTMIDDLE</mx:String>
             <mx:String>DISTELEMEN</mx:String>
             <mx:String>HOUSENO</mx:String>
             <mx:String>POSTAL</mx:String>
             <mx:String>STATE</mx:String>
             <mx:String>ZIP</mx:String>
             <mx:String>JURISDICT</mx:String>
             <mx:String>FULLNAME</mx:String>
             <mx:String>AKPAR</mx:String>
        </esri:outFields>
    </esri:Query>
0 Kudos
Drew
by
Frequent Contributor
<esri:Query
id="query"
returnGeometry="true"
where="STATE_NAME='Carolina'"
outFields='["STATE_NAME","STATE_FIPS","SUB_REGION","STATE_ABBR","POP2000","POP2007"]'/>
0 Kudos
PaulLang
Deactivated User
Works when I hard code the value. 
How can I change the where to use qTextAdd.text, value enter by user?
0 Kudos
Drew
by
Frequent Contributor
Like so..

<esri:Query
id="query"
returnGeometry="false"
where="STATE_NAME = '{qTextAdd.text}'"
outFields='["STATE_NAME","STATE_FIPS","SUB_REGION","STATE_ABBR","POP2000","POP2007"]'/>
0 Kudos
PaulLang
Deactivated User
I tried that before my last response, but it does not work.   Do I need to bind the value?
0 Kudos
Drew
by
Frequent Contributor
works for me..
here is a full application you can test that is derived form the ESRI samples.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml"
    xmlns:esri="http://www.esri.com/2008/ags"
    pageTitle="Query Task (without a map)">
<!--
    Problem:
        How to query the server?
    Solution:
        Send the query using the execute() method on a QueryTask.

    This sample sets up a QueryTask (what layer on what server to query).
    When user clicks the "Get Details" button, a Query is sent with the
    user-provided text to search for.
    Meanwhile a DataGrid has been setup and listens for the results
    (using executeLastResult) from the querytask.
-->
    <!-- Start Declarations -->
        <esri:QueryTask
            id="queryTask"
            url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5"/>
        <esri:Query
            id="query"
            returnGeometry="false"
            where="STATE_NAME = '{stateName.text}'"
            outFields='["STATE_NAME","STATE_FIPS","SUB_REGION","STATE_ABBR","POP2000","POP2007"]'/>
    <!-- End Declarations -->

    <mx:Panel title="Using Query tasks without maps">
        <mx:HBox>
            <mx:Label text="US state name: " />
            <mx:TextInput id="stateName" text="Colorado" />
            <mx:Button label="Get Details" click="queryTask.execute(query);" />
        </mx:HBox>
        <mx:DataGrid id="resultsGrid" dataProvider="{queryTask.executeLastResult.attributes}" visible="{queryTask.executeLastResult != null}" >
            <mx:columns>
                <mx:DataGridColumn headerText="State Name" dataField="STATE_NAME"/>
                <mx:DataGridColumn headerText="Region" dataField="SUB_REGION"/>
                <mx:DataGridColumn headerText="FIPS" dataField="STATE_FIPS"/>
                <mx:DataGridColumn headerText="Abbreviation" dataField="STATE_ABBR"/>
                <mx:DataGridColumn headerText="Population 2000" dataField="POP2000"/>
                <mx:DataGridColumn headerText="Population 2007" dataField="POP2007"/>
            </mx:columns>
        </mx:DataGrid>
     </mx:Panel>
</mx:Application>

0 Kudos
PaulLang
Deactivated User
Must be something to do with the data type of field FULLNAME, because I changed to ZIP and it works fine.
0 Kudos