Select to view content in your preferred language

query integer

1354
9
03-22-2011 01:37 PM
JonPedder
Deactivated User
Hi, I'm looking to query a field in a published featureservice of type integer. I have a text box above the data grid for the user to input a value and have the grid display the results. So far so good, this code does work.

<s:TextInput id="textPeriod" enabled="true"/>
<s:Button id="textButton" label="Go" enabled="true" click="doAssignments()"/>

id="queryAssignments"
   returnGeometry="true"
   outFields="[assignment_number,team_name,timeslider,team_name,description]"
   where="period={textPeriod.text}"

I'd like that if the textPeriod entry is empty, all records are returned, I just don't seem to be able to get this to work.

I've been trying several methods but without any success, such as

where="1=1 AND period={textPeriod.text}"

wild cards don't appear to work on Integers as I've tried passing % and *

Any advice would be greatly appreciated

Jon
Tags (2)
0 Kudos
9 Replies
JohnGarvey
Deactivated User
This is general, but it seems you will need a conditional statement to determine the value of the input box.

if(inputBox.value){
' insert where statement
}
else{
query.where= "x is not null".
}
0 Kudos
JonPedder
Deactivated User
Thanks, i actually did try this but failed to pass the correct parameters along to the query. I've tried the following but get syntax errors. I don't think I can use {textPeriod.text} to pull the data from the input field.

protected function textButton_clickHandler(event:MouseEvent):void
   {
    var resultPeriod:String = public
    if ({textPeriod.text} > 0) {
     resultPeriod = {textPeriod.text}
    }
     else if {
     resultPeriod = "1=1"
     }
   }
0 Kudos
JonPedder
Deactivated User
next effort but still a no go.

protected function textButton_clickHandler(event:MouseEvent,inputPeriod):void
   {
    var resultPeriod:String = public
      
     
    if (inputPeriod > "") {
     resultPeriod = inputPeriod
    }
     else if (inputPeriod= null) {
     resultPeriod = "1=1"
     }
   }

  <s:TextInput id="textPeriod" enabled="true"/>
  
  <s:Button id="textButton" label="Go" enabled="true" click="textButton_clickHandler(event)"/>


<esri:Query
   id="queryAssignments"
   returnGeometry="true"
   outFields="[assignment_number,team_name,timeslider,team_name,description]"
   where="period=resultPeriod"
  />


getting frustrated, going home 😉

Thanks
0 Kudos
JohnGarvey
Deactivated User
I think i am confused. Are you doing this in MXML or actionscript. In actionscript, you do not need the curly braces to refer to the variables.

If as3:
In the conditional part, you could test whether there is textInput.text or whether textInput.text.length>0.

if(textInput.text) or (textInput.text.length>0)

The all-inclusive where clause for the query should still be 'period is not null'
0 Kudos
JonPedder
Deactivated User
Thanks very much John, you can probably tell I'm a newbie and had no idea you didn't need {} within actionscript. I'm pretty close I think but the query itself isn't executing. here's what I have.

Here�??s the defined query
<esri:QueryTask
                  id="queryTaskAssignments"
                  url="http://blah blah/MapServer/6"
                  />
            
            <esri:Query
                  id="queryAssignments"
                  returnGeometry="true"
                  outFields="[assignment_number,team_name,timeslider,team_name,description]"
                  where="resultPeriod"
            />


Here�??s the button and text box
      <s:TextInput id="textPeriod" enabled="true"/>
        <s:Button id="textButton" label="Go" enabled="true" click="textButton_clickHandler(event)"/>


Here�??s the actionscript
            // function to return assignments to data grid
                  public function textButton_clickHandler(event:MouseEvent):void
                  {
                        
                        var resultPeriod:String = "";       
                              
                        if (textPeriod.text>"") {
                              resultPeriod = new String('period ='.concat(textPeriod.text))
                        }
                        if (textPeriod.text=="") {
                              resultPeriod = "1=1"
                        }
                        
                        queryTaskAssignments.execute(queryAssignments);
                  }


I tested with Alert.Show(resultperiod) and get the correct strings to pass to the where= statement, no compiler errors but it�??s not firing the query. Is there something I need to do to pass values from with an actionscrip to mxml?

Thanks again

Jon
0 Kudos
JohnGarvey
Deactivated User
I think we are close.

You will first need to declare the resultPeriod variable outside the function:


private var resultPeriod:string;

public function textButton_clickHandler(event:MouseEvent):void
                  {
                        
                         
                        if (textPeriod.text>"") {
                              resultPeriod = "period="+ textPeriod.text;
                        }
                        if (textPeriod.text==null) {
                              resultPeriod = "period is not null"
                        }


For the query, make the queryAssignment.where=resultPeriod (no quotes).

You also need to assign a handler to the queryTask. You can do this in the MXML by declaring a function in the result property, actionscript by adding an eventlistener, or by binding the executedLastResult of the query task to a component.

hope this helps.
0 Kudos
JonPedder
Deactivated User
Thanks again John. I had just found out about declaring the var outside the function so i did move it.

i see the changes in the function code and 'get' those, not quite sure what you mean about queryAssignment.where=resultPeriod

if I change the query to exactly this I get an error that quotes are expected, if I add quotes I get an error that 'State' where was referenced without being declared.

Again thanks for helping
0 Kudos
JonPedder
Deactivated User
I'm also hopelessly lost on your explanation here. Sorry

"You also need to assign a handler to the queryTask. You can do this in the MXML by declaring a function in the result property, actionscript by adding an eventlistener, or by binding the executedLastResult of the query task to a component."
0 Kudos
JohnGarvey
Deactivated User
Sorry, try this.

Your query is in MXML so you do need the curly brackets to use variables (in the where=):
<esri:Query
                  id="queryAssignments"
                  returnGeometry="true"
                  outFields="[assignment_number,team_name,timeslider,team_name,description]"
                  where="{resultPeriod}"
/>


As for a query Handler. The server sends back information so you need a function that catches the info and does something with it.

Execute the queryTask like this (make sure to import the responder and featureSet):

queryTaskAssignments.execute(queryAssignments, new AsyncResponder( onResult, onFault ));
                function onResult( featureSet : FeatureSet, token : Object = null ) : void
                {
                  Alert.show(featureSet.displayFieldName);
                }
                function onFault( info : Object, token : Object = null ) : void
                {
                    Alert.show( info.toString() );
                }

Put a break point in the onResult function and run in debug mode. This will let you explore what the server returns.
Hope this is a little clearer.
0 Kudos