Select to view content in your preferred language

Feature Layer setDefinitionExpression issue with LIKE operator and wildcards

4200
2
Jump to solution
10-09-2014 12:57 PM
JamesWoodburn
Deactivated User

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

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

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"?

View solution in original post

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor

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"?

0 Kudos
JamesWoodburn
Deactivated User

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.

0 Kudos