protected function buttonclick():void { var querytask:QueryTask = new QueryTask(); querytask.url = "http://tfs-24279/ArcGIS/rest/services/ForestProducts/dynamic_layer_forest_products/MapServer/0" var query:Query = new Query(); query.outSpatialReference = myMap.spatialReference; query.outFields = ["Company"]; query.returnGeometry = true; query.where = expr; var expr:String = new String; querydg.dataProvider = querytask.executeLastResult.attributes; querydg.height=querytask.executeLastResult.attributes.length + 150 querydg.visible= querytask.executeLastResult !=null && querytask.executeLastResult.attributes.length>0 if (qText.text != "" && countycb.selectedItem != " " && industrycb.selectedItem != " ") { expr="Company Like '%{qText.text}%' AND County = '{countycb.selectedItem}' AND prim_bus = '{industrycb.selectedItem}'" } if (qText.text != " " && countycb.selectedItem == " " && industrycb.selectedItem == " " ) { expr= "Company Like '%{qText.text}%' " } if (qText.text =="" && countycb.selectedItem != " " && industrycb.selectedItem == " " ) { expr="County = '{countycb.selectedItem}'" } if (qText.text =="" && countycb.selectedItem == " " && industrycb.selectedItem != " " ) { expr= "prim_bus = '{industrycb.selectedItem}'" } if (qText.text != "" && countycb.selectedItem != " " && industrycb.selectedItem == " ") { expr="Company Like '%{qText.text}%' AND County = '{countycb.selectedItem}'" } if (qText.text != "" && countycb.selectedItem == " " && industrycb.selectedItem != " ") { expr = "Company Like '%{qText.text}%' AND prim_bus= '{industrycb.selectedItem}'" } if (qText.text =="" && countycb.selectedItem != " " && industrycb.selectedItem != " ") { expr = "County = '{countycb.selectedItem}' AND prim_bus= '{industrycb.selectedItem}'" } querytask.execute(query, new AsyncResponder (onResult, onFault)); function onResult(featureSet:FeatureSet, token:Object = null):void { if (featureSet.features.length == 0) { Alert.show("No matching records found. Please try again."); resizableDraggableTitleWindow.visible = false; querydg.visible = false; info.text = " "; } else { querydg.visible = true; resizableDraggableTitleWindow.visible = true; querydg.rowCount = querydg.dataProvider.length; myGraphicslayer.visible = true; import com.esri.ags.utils.GraphicUtil; } if (featureSet.features.length > 1) { info.text = "There are " + featureSet.features.length + " matching records"; } if (featureSet.features.length == 1) { info.text = "There is " + featureSet.features.length + " matching record"; } } function onFault(info:Object, token:Object = null):void { Alert.show(info.toString(), "Query Problem"); } }
Solved! Go to Solution.
Sure.
In the first If statement, it checks if anything was entered in the qText and if so, it puts that into the Expr variable
The next If statement checks if anything was entered in the countycb combobox.. If so, then if there is something in the Expr variable (meaning the first If statement was true), then it appends "AND County = '{countycb.selectedItem}'" to the variable. If not, it just puts "County = '{countycb.selectedItem}'" into the variable.
Finally, the third If statement check if anything was entered in the industrycb combobox. If so, then if there is something in the Expr variable (meaning either of the first two If statement were true), then it appends "AND prim_bus = '{industrycb.selectedItem}'" to the variable. If not, it just puts "prim_bus = '{industrycb.selectedItem}'" into the variable.