Understanding feature layer methods

Discussion created by samirgambhir on Jan 2, 2014
I suspect I am not using Feature Layer methods correctly. My application has two feature layers ??? State and sub-state. The user selects the State from a pull-down menu. The selected state is used in the definition expression for selecting all sub-state features within the state. A subset of sub-state features is then selected from the original sub-state features which match certain user-selected criteria. I wrote the code below which does what it is intended to do, and displays the selected features too, but provides a long list of errors in the console. The major error that I see is the usage of ???setDefinitionExpression??? twice for the same feature layer. Is it really a problem? Can this code be written in more efficient way?
Here is the simplified reproducible code. I am using JavaScript API. I'll really appreciate it if someone can help me resolve this.

strNewGeog = "State_name= '" + newGeog + "'";//newGeog is the variable that stores the name of the selected State from pull-down menu
distFeatureLayer.queryFeatures(query, function(featureSet) {
  for ( k = 0; k < featureSet.features.length; k++) {
    var indValue = featureSet.features[k].attributes[someField];
    if (indValue <= userSuppliedValue) {
      selDist.push(featureSet.features[k].attributes.subState);//selDist is an array
    } //if
  } //for
  strDist = "subState = '" + selDist[0]; //A string
  if (selDist.length > 1) {
    for ( i = 1; i < selDist.length; i++) {
      strDist += "OR subState = '" + selDist[i];
    } //for
  } //if
  distFeatureLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW);
  distFeatureLayer.setRenderer(renderer); //renderer is already defined 
}); //queryFeatures