I'm running into an issue with setDefinitionExpression on a Feature Layer... If the value starts with a wildcard, all features will be returned (basically, the definition expression is not applied - if the layer has a default expression, that will still be applied). So, I'm doing something like this:
featureLayer.setDefinitionExpression("FACILITYID LIKE'%a%'");
OR
featureLayer.setDefinitionExpression("FACILITYID LIKE'%a'");
This expression works in query tasks and when applied as a definition query for the service layer, so I'm thinking this is a bug with the API, but maybe I'm missing something.
Also, the following works, so this appears to fail only when the value starts with a wildcard:
featureLayer.setDefinitionExpression("FACILITYID LIKE'a%'");
Any ideas?
Thanks,
Jim
Solved! Go to Solution.
That doesn't seem to be the case in this sample. Working in the sandbox, you'll get different features with
featureLayer.setDefinitionExpression("PROD_GAS Like '%Y%'");
versus
featureLayer.setDefinitionExpression("PROD_GAS Like '%N%'");
Using "PROD_GAS Like '%Y%'" gives the same result as "PROD_GAS Like '%s'" (this field contains "Yes" or "No").
In your example, do you get any features returned with FACILITYIDs that don't contain an "a"?
That doesn't seem to be the case in this sample. Working in the sandbox, you'll get different features with
featureLayer.setDefinitionExpression("PROD_GAS Like '%Y%'");
versus
featureLayer.setDefinitionExpression("PROD_GAS Like '%N%'");
Using "PROD_GAS Like '%Y%'" gives the same result as "PROD_GAS Like '%s'" (this field contains "Yes" or "No").
In your example, do you get any features returned with FACILITYIDs that don't contain an "a"?
In my case I was get back all features, whether they include and 'a' or not.
Thanks for that sandbox example, it helped isolate my testing. I noticed that sandbox example starts to act strangely once I change the layer mode to SNAPSHOT, so I changed my layer from SNAPSHOT to ONDEMAND on a wild guess and the filter worked as expected. However, when I switched it back it was still working properly. I guess I'm going to chalk this up to a strange cache issue or something.