Select to view content in your preferred language

Definition expression not working

785
4
Jump to solution
11-15-2022 04:05 PM
maglourenco
Emerging Contributor

Greetings,

I'm developing an Android app (Java) using the Runtime SDK for Android.

I'm trying to create a definition condition for a FeatureLayer, to only show features with 'Tipo = Autotanque' and with 'Capacidade > 500 (liters)'.

I tried the following lines of code:

Spoiler
featureLayer.setDefinitionExpression("Tipo = 'Autotanque' WHERE CAPACIDADE > '500'");
Spoiler
featureLayer.setDefinitionExpression("Tipo = 'Autotanque' AND CAPACIDADE > '500'");

After testing only the first part of the expression (Tipo = 'Autotanque'), it worked, but the second part of the definition expression is not being read properly as no features are shown.

 

Please guide me on how to build this expression.

Thank you very much in advance.

 

Cheers

0 Kudos
1 Solution

Accepted Solutions
MichaelBranscomb
Esri Frequent Contributor

Hi,

What field type is CAPACIDADE? If it's numeric then you may need to omit the ' ' around the value

e.g. req_Type = 'Tree Maintenance or Damage' AND req_id > 40000

You can test this specific example here: Query: Incidents (ID: 0) (arcgis.com)

 

Cheers

View solution in original post

0 Kudos
4 Replies
MichaelBranscomb
Esri Frequent Contributor

Hi,

What field type is CAPACIDADE? If it's numeric then you may need to omit the ' ' around the value

e.g. req_Type = 'Tree Maintenance or Damage' AND req_id > 40000

You can test this specific example here: Query: Incidents (ID: 0) (arcgis.com)

 

Cheers

0 Kudos
maglourenco
Emerging Contributor

I accepted this answer as the solution. I found out I had some features not prepared to be queried. After deleting the malfunctioning features, my query went through as successful.

I used the following query 

"Capacidade > 500 AND Tipo LIKE 'Autotanque'"

I decided it was more convenient to use FeatureLayer.queryFeaturesAsync rather than the FeatureLayer.setDefinitionExpression.

Cheers

0 Kudos
maglourenco
Emerging Contributor

Hello Michael,

 

Thank you very much for your reply.

I decided it's more convenient to use QueryPameters in FeatureLayer.queryFeaturesAsync for the purpose I want.

Regarding your question, it is a numeric field. I also tried without the quotes ' and had the same result (forgot to mention that).

Thank you very much for your reply

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

... if you're looking for client-side display filtering you might also consider using Display Filters: Query | ArcGIS Runtime API for .NET | ArcGIS Developers

0 Kudos