<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Invalid Query Parameters while executing query in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/invalid-query-parameters-while-executing-query/m-p/1333723#M82354</link>
    <description>&lt;P&gt;if you are querying a text field try:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;params.where = attributeName.value + expressionsign.value + "'" + value.value + "'";&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 29 Sep 2023 13:18:03 GMT</pubDate>
    <dc:creator>johnbrosowsky</dc:creator>
    <dc:date>2023-09-29T13:18:03Z</dc:date>
    <item>
      <title>Invalid Query Parameters while executing query</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/invalid-query-parameters-while-executing-query/m-p/1333694#M82351</link>
      <description>&lt;P&gt;Hi Community,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am referring the following sample :&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/query/" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/javascript/latest/sample-code/query/&lt;/A&gt;&amp;nbsp;which essentially&amp;nbsp;&lt;SPAN&gt;queries a hosted feature service based on attributes of features in the service.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am trying to replicate the same on a service that I have published however, I am getting the error of &lt;STRONG&gt;Invalid Query&lt;/STRONG&gt; &lt;STRONG&gt;Parameters&lt;/STRONG&gt; in the console. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;On looking into the script it looks like that the query is not being constructed properly. My best guess is the attribute that I am trying to query is a text field and for some reason that is not getting incorporated in the query hence, am getting this error.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Following is the code that I am executing:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;        require(["esri/config", "esri/Map", "esri/views/MapView", "esri/layers/FeatureLayer", "esri/layers/GraphicsLayer", "esri/rest/query", "esri/rest/support/Query"], function(esriConfig, Map, MapView, FeatureLayer, GraphicsLayer, query, Query){
    
    esriConfig.apiKey = ""

    const floraURL = "xxxx"

    const popupTemplate = {
        title: "{Classification}, {Name}", 
        fieldInfos: [
            {
                fieldName: "Classification",
                label: "Classification"
            },
            {
                fieldName: "ParasiteInfection",
                label: "Parasite Infection Identified"
            },

            {
                fieldName: "Threats",
                label: "Threats Identified"
            }
    ],
    content: "{ParasiteInfection}" + "{Threats}" + "{Classification}"
    };


    const resultsLayer = new GraphicsLayer();

    const params = new Query({
          returnGeometry: true,
          outFields: ["*"]
        });

    var map = new Map({
        basemap: "arcgis-topographic",
        layers: [resultsLayer]
    });

    var view = new MapView({
        map: map,
        center: [77.18108, 28.53337],
        zoom: 15,
        container: "viewDiv",
        popup: {
            dockEnabled : true,
            dockOptions: {
                position: "top-right",
                breakpoint: false
            }
        }
    }); 

    view.when(function(){
        view.ui.add("optionsDiv", "bottom-right");
        document.getElementById("doBtn").addEventListener("click", doQuery);
    });

    
    const attributeName = document.getElementById("attSelect");
    const expressionsign = document.getElementById("signSelect");
    const value = document.getElementById("valSelect");

    function doQuery(){
        params.where = attributeName.value + expressionsign.value + value.value;

        query
            .executeQueryJSON(floraURL, params)
            .then(getResults)
            .catch(promiseRejected);
        }

    function getResults(response){
        const results = response.features.map(function (feature){
            feature.symbol = {
                type: "simple-marker", // Use simple-marker for 2D symbology
                color: "green", // Set the color of the marker
                size: 10, // Set the size of the marker
                outline: {
                    color: [0, 0, 0, 0.5], // Set the outline color and transparency
                    width: 1 // Set the outline width
                }
            };

            feature.popupTemplate = popupTemplate;
            return feature;
        });

        resultsLayer.addMany(results)

        view.goTo(results).then(function(){
            view.openPopup({
                features: results,
                featureMenuOpen: true,
                updateLocationEnabled: true
            });
        })
        .catch(function (error){
            if (error.name !== "AbourtError"){
                console.error(error);
            }
        });

        document.getElementById("printResults").innerHTML = results.length + "Results Found";

    }

    function promiseRejected(error){
        console.error("Promise Rejected: ", error.message);
    }
    });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Am not really what am I missing here as I have just tried to replicate what is present in the sample. Additionally, am very new to API for JavaScript&amp;nbsp;and trying to learn through the samples hence, there is a good possibility that something basic is missing&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Any inputs would be appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2023 11:32:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/invalid-query-parameters-while-executing-query/m-p/1333694#M82351</guid>
      <dc:creator>wizgis</dc:creator>
      <dc:date>2023-09-29T11:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid Query Parameters while executing query</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/invalid-query-parameters-while-executing-query/m-p/1333718#M82353</link>
      <description>&lt;P&gt;Since you're querying a text field, you have to encase the value in quotes.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;params.where = attributeName.value + expressionsign.value + "'" + value.value + "'";&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can also do this with &lt;A href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals" target="_self"&gt;template literals&lt;/A&gt;, which makes the expression a little easier to visualize&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;params.where = `${attributeName.value} ${expressionsign.value} '${value.value}'`;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2023 13:11:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/invalid-query-parameters-while-executing-query/m-p/1333718#M82353</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2023-09-29T13:11:16Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid Query Parameters while executing query</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/invalid-query-parameters-while-executing-query/m-p/1333723#M82354</link>
      <description>&lt;P&gt;if you are querying a text field try:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;params.where = attributeName.value + expressionsign.value + "'" + value.value + "'";&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2023 13:18:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/invalid-query-parameters-while-executing-query/m-p/1333723#M82354</guid>
      <dc:creator>johnbrosowsky</dc:creator>
      <dc:date>2023-09-29T13:18:03Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid Query Parameters while executing query</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/invalid-query-parameters-while-executing-query/m-p/1334432#M82375</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/16875"&gt;@johnbrosowsky&lt;/a&gt;&amp;nbsp;&amp;amp;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/2839"&gt;@KenBuja&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This worked and I am able to successfully query the layer.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2023 07:12:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/invalid-query-parameters-while-executing-query/m-p/1334432#M82375</guid>
      <dc:creator>wizgis</dc:creator>
      <dc:date>2023-10-03T07:12:26Z</dc:date>
    </item>
  </channel>
</rss>

