Query Feature Class

157
2
Jump to solution
04-11-2020 04:01 PM
jaykapalczynski
Frequent Contributor

I know this is going to be a hard one to follow.....but hope someone can...

I am now trying to select features from that Feature Class via JS 4.14 api and write them to a Graphic...this is working SORT OF....

For some reason I can select the features from certain fields and not from others....I am very confused.

I have 3 combo boxes in the app that push values to queries to query the data.

All the values you see in the ComboBoxes exist in the FC itself.  I will post and example below

I can only get features selected from the combo box with the miles (DISTANCE) values.

COMBO BOXES

<select id="mySelect" onchange="window.JsController.cboChanged()">
    <option value="9a35172e071f4a33b191172a9b4b02ae">feature 1</option>
    <option value="6a35172e071f4a33b191172a9b4b02ae">feature 2</option>
    <option value="1a35172e071f4a33b191172a9b4b02ae">feature 3</option>
</select>

<select id="mySelect2" onchange="window.JsController.cboChanged2()">
    <option value="10">10 miles</option>
    <option value="50">50 miles</option>
    <option value="20">20 miles</option>
    </select>

<select id="mySelect3" onchange="window.JsController.cboChanged3()">
    <option value="1520 Split Oak Ln, Henrico, Virginia, 23229">address 1</option>
    <option value="113 Buffalo Rd, Clarksville, Virginia(VA), 23927">address 2</option>
    <option value="8817 Sherando Dr, Bristow, Virginia(VA), 20136">address 3</option>
</select>

I am calling the JS code from .net C# as follows...the on Return features calling the function displayResultsUniqueID for all 3 combobox change events

window.JsController = {
// SEARCH BY UNIQUE ID
        cboChanged: function () {
            resultsLayer2.removeAll();
            var x = "";
            x = document.getElementById("mySelect").value;
            queryMultipartPolyongUniqueID(x).then(displayResultsUniqueID);
        },
// SEARCH BY DISTANCE
        cboChanged2: function () {
            resultsLayer2.removeAll();
            var x = "";
            x = document.getElementById("mySelect2").value;
            queryMultipartPolyongUniqueID2(x).then(displayResultsUniqueID);
        },
// SEARCH BY ADDRESS
        cboChanged3: function () {
            resultsLayer2.removeAll();
            var x = "";
            x = document.getElementById("mySelect3").value;
            queryMultipartPolyongUniqueID3(x).then(displayResultsUniqueID);
        }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
};  ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I am then attempting to Query my Feature Class as follows from each of the ComboBox OnChange Event

function queryMultipartPolyongUniqueID(feature) {
     var str = feature;
     var query = "";
     query = MultiPartPolygonsLayer.createQuery();
     query.where = "UNIQUEIDparameter = " + str; 

     return MultiPartPolygonsLayer.queryFeatures(query);
}
function queryMultipartPolyongUniqueID2(feature) {
    var str = feature;
    var query = "";
    query = MultiPartPolygonsLayer.createQuery();
    query.where = "DISTANCEparameter = " + str;

    return MultiPartPolygonsLayer.queryFeatures(query);
}
function queryMultipartPolyongUniqueID3(feature) {
    var str = feature;
    var query = "";
    query = MultiPartPolygonsLayer.createQuery();
    query.where = "ADDRESSgeocode  = " + str;

    return MultiPartPolygonsLayer.queryFeatures(query);
}
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I then do the same for all 3 combo boxes

They all call the same function to display the results

then(displayResultsUniqueID);

function displayResultsUniqueID(results) {

     resultsLayer2.removeAll();
     var features2 = results.features.map(function (graphic) {
        graphic.symbol = {
           type: "simple-fill",
           style: "solid",
           color: [240, 248, 255, 0.9],
           size: "10px", // pixels
               outline: {
                // autocasts as new SimpleLineSymbol()
               color: [240, 248, 255, 0.9],
               width: 1 // points
           }
         };
           return graphic;
      });

      var numCounties2 = features2.length;
      alert(numCounties2 + " Counties found");
      document.getElementById("demo").innerHTML = numCounties2 + " features found from query";
      resultsLayer2.addMany(features2);
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

This is from the Feature Class I am trying to query showing the 3 fields and their types

This is an example of the Feature Service Queried from ArcGIS Server to Show that the Values DO in fact exist

If I change the values in the UNIQUEIDparameter field to something like 4,5,6 and then change the Comobox to reflect those values the query WORKS.  BUT when I use a longer string it fails

<select id="mySelect" onchange="window.JsController.cboChanged()">
    <option value="4">feature 1</option>
    <option value="5">feature 2</option>
    <option value="6">feature 3</option>
</select>

WHY ARE certain fields queryable and other are not....they are all String fields...And on top of that if I shorted the length of the UNIQUEIDparameter field values to 4,5,6 and then change the combobox values it works for the UNIQUEIDparameter.  Longer values do not work....

Ultimately I need to query a GUID field.

I can post the solution if need be....but thought someone might have some ideas for me to check

0 Kudos
1 Solution

Accepted Solutions
jaykapalczynski
Frequent Contributor

that was it ....I went back to ArcGIS Server and tried to run the queries there....I had to place  ' ' around the value to get it to work....then I brought that back to Javascript and it works...

query.where = "idvalues= ' " + strresults + " ' ";

View solution in original post

0 Kudos
2 Replies
jaykapalczynski
Frequent Contributor

Think I figured it out....had to put  ' ' around the value

 query.where = "NWTL_ID = ' " + str + " ' ";

0 Kudos
jaykapalczynski
Frequent Contributor

that was it ....I went back to ArcGIS Server and tried to run the queries there....I had to place  ' ' around the value to get it to work....then I brought that back to Javascript and it works...

query.where = "idvalues= ' " + strresults + " ' ";

0 Kudos