AnsweredAssumed Answered

Query task with JavaScript API

Question asked by geoffreywestgis on Oct 21, 2014

I would ultimately like to query my feature layer for other fields when a specific field is chosen from my feature layer.

 

If my request type is chosen as E-WASTE, my function to populate that drop down is below

 

function PopulateRequestTypes(serviceRequestLayerFields) {
    var serviceRequestFields
    for (var i = 0; i < serviceRequestLayerFields.length; i++) {
        if (serviceRequestLayerFields[i].name == serviceRequestLayerInfo.RequestTypeFieldName) {
            serviceRequestFields = serviceRequestLayerFields[i].domain.codedValues;
            break;
        }
    }


    var serviceRequestTypes = { identifier: "id", items: [] };
    for (var i = 0; i < serviceRequestFields.length; i++) {
        serviceRequestTypes.items[i] = { id: serviceRequestFields[i].name, name: serviceRequestFields[i].name };
    }
    var serviceRequestStore = new dojo.data.ItemFileReadStore({ data: serviceRequestTypes });
    dijit.byId('cbRequestType').attr('store', serviceRequestStore);
}




 

 

 

This is my function to add my feature layer

function AddServiceRequestLayerOnMap() {
    var serviceRequestLayer = new esri.layers.FeatureLayer(serviceRequestLayerInfo.LayerURL, {
        mode: esri.layers.FeatureLayer.MODE_SNAPSHOT,
        outFields: [serviceRequestLayerInfo.OutFields],
        id: serviceRequestLayerInfo.Key,
        displayOnPan: false,
        visible: false
    });
    map.addLayer(serviceRequestLayer);



 

 

 

 

I would like my query task to see that I have selected E-WASTE and populate my combo box with E-WASTE subtypes

I did a bit of digging and retrieved this query task example which essentially populates a combo box from a feature query.  My question is how do I link the two.

 

 

 

 

dojo.require("esri.map");
dojo.require("esri.tasks.query");
dojo.require("dojo.parser");
dojo.require("dijit.form.ComboBox");
dojo.require("dojo.data.ItemFileReadStore");




function populateList(results) {
    //Populate the ComboBox with unique values
    var zone;
    var values = [];
    var testVals = {};
    //Add option to display all zoning types to the ComboBox
    values.push({
        name: "ALL"
    })


    //Loop through the QueryTask results and populate an array
    //with the unique values
    var features = results.features;
    dojo.forEach(features, function(feature) {
        zone = feature.attributes.webappfield;
        if (!testVals[zone]) {
            testVals[zone] = true;
            values.push({
                name: zone
            });
        }
    });
    //Create a ItemFileReadStore and use it for the
    //ComboBox's data source
    var dataItems = {
        identifier: 'name',
        label: 'name',
        items: values
    };
    var store = new dojo.data.ItemFileReadStore({
        data: dataItems
    });
    dijit.byId("mySelect").set('store', store);
}


function init() {
    queryTask = new esri.tasks.QueryTask("http://localhost:6080/arcgis/rest/services/webAppService/MapServer/0");
    query = new esri.tasks.Query();
    query.returnGeometry = false;
    query.outFields = ["webappfield "];
    query.where = "webappfield <> ''";
    queryTask.execute(query, populateList);
}
dojo.addOnLoad(init);

Outcomes