How to query for Features in a Domain string attribute field

257
6
04-28-2020 06:05 AM
PHerk
by
New Contributor II

 For my customer I am building an application where I query a Featurelayer.

function queryFeatureLayer() {
var query = {
spatialRelationship: "intersects",
outFields: ["*"],
returnGeometry: true,
where: field = value
};
featurelayer.queryFeatures(query).then(function(result) {
// handle results
});
}

This works for a simple attribute field (string) .

Assume field = "animal", value = "dog"

where: "animal" = "dog"

This returns all features that have the string "dog" in this field.

Now the "animal" field is changed to hold a  string-list, a domain. In AGOL this gives a popup list with a few animals Assume: ("dog", "cat", "mouse").

I want to query this field but I get errors using:

where: "animal = dog"

or

where: "animal = 1"

The error:

Cannot perform query. Invalid query parameters.

How can I set up a working query to search for all Features that have "dog" set in field "animal" using a Domain string attribute field?

Thanks

0 Kudos
6 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

What is the value actually stored in the feature for the attribute? When you look at that table in ArcMap does it have 1 for a Dog?

It sounds like you are saying that the domain is a coded domain using a string thus the query would need to be:

animal = '1'

0 Kudos
PHerk
by
New Contributor II

Hi Robert,

I tried animal = '1', to test if an index number would return values, but it's not the case...

My customer set it up in AGOL. I changed it to animals to simplify the question. I made a screenshot of the actual attribute in AGOL. It is a 'status' attribute with a pre-defined string value list (Domain). Sorry it is in Dutch.

In AGOL, selecting this attribute in the table, shows a popup with the 3 strings.

Screenshot from AGOL atribute

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

So does status = 'gepland' work?

0 Kudos
PHerk
by
New Contributor II

No, I tried all 3 strings, "nieuw", "gepland" and "uitgevoerd" but all fail.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

And status = '1' does not work? (single quotes is important).

0 Kudos
PHerk
by
New Contributor II

No, but the single ' solved it.

I was misled because I got results without the single quotes on an Attribute Field without a domain list attached.

For others with the same issue:

where: "animal = dog" works on an Attribute Field which is just a string.

where: "animal = dog" fails on an Attribute Field which has a Domain list attached.

 

solution:

Always use: "animal = 'dog'"

Thank you Robert. Appreciated!

0 Kudos