How to write conditional query using Javascript?

1834
4
07-06-2017 06:49 AM
MKF62
by
Occasional Contributor III

**EDIT**

I no longer think this a query issue. I have viewed the error in the browser's developer tools and get this: "Refused to execute script from 'https://myURLhere.org' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.

I have no idea what this error means or if it's even something I can fix. The <script> tags should mean that it's read as javascript (i've also specified type=text/javascript just in case). I don't get why it can read the JS for the current webmap fine but if I change something in the query it can't read the JS for the webmap anymore. I'm editing the HTML doc in notepad++ and then refreshing the browser after I've saved it to view changes. 

-----

I'm taking over a project for a colleague who left for another position, but know very little about ArcGIS API for Javascript. He's already made a map, and it seems to work just fine how he's written it, but whenever I try to add state abbreviations to the query, it's breaks the map and nothing shows up but the base map. I have a feeling it has to do with how the query is written, but it's strange because I don't get how it's showing anything at all if the query is the problem.

Currently the query looks like this:

query.where = "STATE_ABBR = 'GA' OR STATE_ABBR = 'IA' OR STATE_ABBR = 'KY'..."

It goes on like that for a while with more state abbreviations listed. I've seen the query.where statement help page where it says to use this type of quotation format: "STATE_ABBR = ' "GA" ' " OR STATE_ABBR = ' " IA " ' " etc. but all that breaks the map and makes the state abbreviations into non-strings which is the opposite of what I'd want. 

I've also tried putting the definition of queryTask before the definition of query and the where clause based on the help pages but it doesn't work. This is how the whole query is set up and executed (please note, the where clause and queryTask.execute are never encased in function executeQueryTask() which I've also tried to no avail):

var query = new Query();
query.where = "STATE_ABBR = 'GA' OR STATE_ABBR = 'IA' OR STATE_ABBR = 'KY' OR STATE_ABBR = 'MO' OR STATE_ABBR = 'TX' OR STATE_ABBR = 'VA' OR STATE_ABBR = 'NE' OR STATE_ABBR = 'OK' OR STATE_ABBR = 'OH' OR STATE_ABBR = 'AR' OR STATE_ABBR = 'DE' OR STATE_ABBR = 'NJ' OR STATE_ABBR = 'SC' OR STATE_ABBR = 'MS' OR STATE_ABBR = 'TN'";

query.returnGeometry = true;
query.outFields = ["STATE_NAME", "STATE_ABBR"];

var queryTask = new QueryTask("https://fakeurl/rest/services/BaseLayers/USAStatesGeneralized/MapServer/0");
queryTask.execute(query, showResults);

0 Kudos
4 Replies
ThomasSolow
Occasional Contributor III

You could try escaping the quotes around the abbreviates.

Something like "STATE_ABBR = \"GA\" OR STATE_ABBR = \"IA\""

0 Kudos
MKF62
by
Occasional Contributor III

Sadly, that does not work. Thanks for the help though. I don't actually think it's a query problem anymore... I've reviewed the error I get in the inspector on the webpage and I get "Refused to execute script from 'https://myURLhere.org/" because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled." 

I have no idea what this error means or if it's even something I can fix. The <script> tags should mean that it's read as javascript (i've also specified type=text/javascript just in case). I don't get why it can read the JS for the current webmap fine but if I change something in the query it can't read the JS for the webmap anymore. I'm editing the HTML doc in notepad++ and then refreshing the browser after I've saved it to view changes. 

0 Kudos
KenBuja
MVP Esteemed Contributor

For a query.where statement like that, you can use this syntax:

query.where = "STATE_ABBR in ('GA', 'IA', 'KY', ... , 'TN')";

MKF62
by
Occasional Contributor III

Sadly, that does not work. Thanks for the help though. I don't actually think it's a query problem anymore... I've reviewed the error I get in the inspector on the webpage and I get "Refused to execute script from 'https://myURLhere.org/because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled." 

I have no idea what this error means or if it's even something I can fix. The <script> tags should mean that it's read as javascript (i've also specified type=text/javascript just in case). I don't get why it can read the JS for the current webmap fine but if I change something in the query it can't read the JS for the webmap anymore. I'm editing the HTML doc in notepad++ and then refreshing the browser after I've saved it to view changes. 

0 Kudos