AnsweredAssumed Answered

FindTask/FindParameters with layerDefinition

Question asked by schlot on Jul 30, 2015
Latest reply on Jul 30, 2015 by schlot

I have a featureLayer that may have a definition expression, controlled by a list of provider types.    I am using Typeahead to create a list of values for the user to select from using the values from my provider field, which executes a find. 


Since there might be a filter already applied, I'd like to limit the choices in my list of values to only those that meet my current definition expression on my layer.  It looks like layerDefinitions on my findParameters ought to allow me to use the same expression as I have already on my featureLayer.


My findtask and parameters are defined as:


app.findTask = new FindTask(config.findFeatureLayerUrl);
          app.findParams = new FindParameters();
          app.findParams.returnGeometry = true;
          app.findParams.outSpatialReference = app.spatialReference;
          app.findParams.layerIds = [0];
          app.findParams.searchFields = ['NA_PROVIDER'];


The layer I'm searching on is layer 0.  I may or may not have a definition expression set. I want the list that typeahead is producing to be limited to only those that meet the current definition.  The definition is dynamic, so I can just add it when I'm defining it initially.


I've tried this: 

            source: function(q, process) {
             app.findParams.searchText = q;
                  var def = app.featureLayer.getDefinitionExpression();
              if (def) {
                 app.findParams.layerDefinitions[0] = def;// error occurs here
              app.findTask.execute(app.findParams).then(function(x) {
                results = x;
                process( {
                  return a.value;


I get an Uncaught TypeError:   cannot set property '0' of null when attempting to the layerDefinitions.  Either I don't have the right syntax for that, my definitionExpression from the featureLayer is too complicated (it is a where clause with several AND and ORs in it) or I can't set my layerDefinitions at this point in the code.


I couldn't find any threads for findParameters and layerDefinitions, which tells me it isn't used much.