AnsweredAssumed Answered

check if field exist and then run query

Question asked by sibghatullah86 on Apr 11, 2017
Latest reply on Apr 11, 2017 by rscheitlin
I am running a query but some map services doesn't contain field name "FeederID".So my query task is not running.
I have tried to get field names  by using getFieldList() and store it in an array and then use if conditions  using
jQuery. i have also tried to copy my code inside  if(fieldtest.name=="FeederID") but not worked.

what i am looking is if  query is true on query3.where = "FeederID='HITAM POW F2'".


jQuery code:
if
($.inArray('example', myArray) != -1){  // found it}

 

My code:

 

on(dom.byId("search1"), "click", function () {
var typesData = [];
var allPromises = [];
var j=0;
var y=1;
for(j=15;j<19;j++){
var url="http://localhost:6080/arcgis/rest/services/RAEC/MapServer/"+j;
var queryTask3 = new QueryTask(url);
var query3 = new Query();
query3.returnGeometry = false;
getFieldList();
var options = [];
function getFieldList() {
esri.request({
url: "http://localhost:6080/arcgis/rest/services/RAEC/MapServer/"+j,
content: { f:"json" },
handleAs: "json",
callbackParamName: "callback",
load: function(response, io) {
var fields = response.fields;

dojo.forEach(fields, function(fieldtest) {
if(fieldtest.name=="FeederID")
{
options.push(fieldtest.name);
}
});
}
});
}
query3.where = "FeederID='HITAM POW F2'" ;
var promise = queryTask3.executeForCount(query3,function (count) {
//alert(count);
var typeCount={ field: y,
field1: count };
typesData.push(typeCount);
y++;
});

allPromises.push(promise);
options=[];

}
all(allPromises).then(function(){
var grid= new Grid({
columns: {
field: 'Serial', field1: 'Count' }
}, 'grid');
grid.renderArray(typesData);
});
});

Outcomes