AnsweredAssumed Answered

On complete query task event contains many query tasks

Question asked by Sara_EL_MALKI on Sep 26, 2017
Latest reply on Sep 26, 2017 by Sara_EL_MALKI

Hi guys,

 

I am struggling with same problem since I started using the API, 

my concept is: I wanna make a query which has some results, for each result I wanna do another query, and for each result of that last query I wanna do some instructions so the idea is that the hole process is based on the first query, whenever I finish my instructions I wanna display the object id of the FIRST QUERY which lead me to the last one, 

 

When I try this in the API, I notice that it doesn't happen like that instead they run all the queries, then they go to the second then to the third as if they's not inside each other, I'll give you the code which I am using to draw a dojo chart, that you can understand my problem clearly,

In the code below I wanna for Each Collection circuit, Search if it has Sections then If it does, Search for each Section if it has bags, then for each bag look if it has a "C" or "NC" in a column then calculate the SUM of the bags having "C" and those having "NC" in the COLLECTION CIRCUIT,

so I need an ARRAY containing the name of the circuit and the sum of C and NC bags, 

the code below is giving me the sum of C and NC bags for each SECTION  not for each Collection Circuits,

please HELP ME and clarify what's the error that I'm doing !

Thomas Solow John Zhang  Robert Scheitlin, GISP Rebecca Strauch, GISP 

 

function do_the_magic_1(){

array_id_troncon=[];

var queryCircuit_6 = new Query();

var QTask_Collecte = new QueryTask("..../MapServer/1"); //Collection Circuits
var queryTaskCircuit_6 = new QueryTask("..../MapServer/11"); //SECTIONS
var queryTaskBac_6 = new QueryTask(".../MapServer/6"); //BAGS

 

queryCircuit_6.where = "direction IS NULL AND renfort_repassage = 0 AND arrondissement='MGHOGHA'"
queryCircuit_6.outSpatialReference = {wkid:102100};
queryCircuit_6.returnGeometry = false;
queryCircuit_6.outFields = ["*"];
QTask_Collecte.execute(queryCircuit_6); // We have found all the "Collection Circuits"

QTask_Collecte.on("complete",function(eventCircuitCol){

var fsetCircuitC = eventCircuitCol.featureSet;
var FeaturesCC = fsetCircuitC.features;

for (var i = 0, len = FeaturesCC.length; i < len; i++) { // for each Circuit => Search if it has a Section

var FeatureCC = FeaturesCC[i];
var queryCircuit_6 = new Query();
queryCircuit_6.where = "id_circuit_collecte='"+FeatureCC.attributes['objectid']+"'"; //Sections of the circuit
queryCircuit_6.outSpatialReference = {wkid:102100};
queryCircuit_6.returnGeometry = false;
queryCircuit_6.outFields = ["*"];
queryTaskCircuit_6.execute(queryCircuit_6); //We have found all the sections of that circuit 
}
});

queryTaskCircuit_6.on("complete",function(eventTroncon){

var fsetTroncon = eventTroncon.featureSet;
var FeaturesTr = fsetTroncon.features

for (var ii = 0, leni = FeaturesTr.length; ii < leni; ii++) { //for each Section => Search if it has Bags !
var featureTr = FeaturesTr[ii];
var queryBac_6 = new Query();
queryBac_6.where = "id_troncon='"+featureTr.attributes['id_troncon']+"'"; //BAGS that belongs to the section
queryBac_6.outSpatialReference = {wkid:102100};
queryBac_6.returnGeometry = false;
queryBac_6.outFields = ["*"];

queryTaskBac_6.execute(queryBac_6,function(fset){
conforme_oui_1=0; // I wanna initialise these too variables whenever I change the Collection Circuit
conforme_non_1=0;
for(i=0;i<fset.features.length;i++){ // For each bag => look if it has a "C" or "NC" in a specific column 
var featureBac=fset.features[i];

if(featureBac.attributes['positionnement']=='C'){
conforme_oui_1=conforme_oui_1+1;
}
else if(featureBac.attributes['positionnement']=='NC'){
conforme_non_1=conforme_non_1+1;
}
 
}
Conforme_oui_Array.push(conforme_oui_1);
Conforme_non_Array.push(conforme_non_1);

//Rendering
chartPos_ParCircuit.addSeries("Series A", Conforme_oui_Array, {color:"green"} ).addSeries("Series B", Conforme_non_Array,{color:"red"}).render();
});

 

}

}); //end on complete

 

} //end function //

Outcomes