Query to non spatial table return nothing

2110
3
02-14-2013 05:51 PM
mohd_syafidabdullah
New Contributor III
Hi there,
I hope somebody can help me.
I write a query to non spatial table that contain information on geometry that I click.
But no value return for var resultA.
Here's the code:
function kadcmkinfo1(lotno){
  qKADCMKinfo =  new esri.tasks.QueryTask("http://xx.xx.xx.xx:8399/arcgis/rest/services/v_pv/MapServer/9");//layer 9 V_PV_LOT_PROPLST_PROPLST_DETL
  var content1 = "";
  var queryInfo = new esri.tasks.Query();
  
  
  //queryInfo.returnGeometry = false;
  queryInfo.outFields = ["*"];
  //queryInfo.where = "LOT_NO_FORMATED = '" +lotno+ "'";                 //"NOLOT='"+ lotNo.replace("LOT", "Lot") +"' and h_lokasi='PRESINT "+ prct +"'";
  queryInfo.where = "LO_NO = 0007460";
  
  qKADCMKinfo.execute(queryInfo);
  
  dojo.connect(qKADCMKinfo,'onComplete',function(fInfo){  //onComplete
  var ptLot = "", ptBldgNo = "", ptValType = "", ptAnnlVal = "", ptDesc = "";
  var resultA = fInfo.features; 
  if (resultA.length == 0) alert("no value");
  alert(lotno);
  
  content1 = "<table border='1'><tr><th><b>"+lotno+"</b></th></tr>";
  for (var i=0; i=resultA.length; i++){
      alert(i);
   var grpc = resultA;
   ptLot = grpc.attributes["LOT_NO_FORMATED"];
   alert(ptLot);
   content1 += "<tr><td> Valuation Type :</td><td>" + ptLot + "</td>";
      content1 += "</tr>";
  
  }
   
  
  
  
  
  content1 +="</table>";          
  });
  
  
  
  
  
  
  return(content1);
  }

Is it something wrong in my code?

Please help me
0 Kudos
3 Replies
DianaBenedict
Occasional Contributor III
I would use the already "hooked" up portion of the callback within the queryTask.execute. The usage for .execute is below

execute(parameters, callback?, errback?)

The "callback?" is where you would place your code that you have attempted to use the dojo.connect to below:

,function(fInfo){  ...etc..

You might want to try something like this instead

  qKADCMKinfo.execute(queryInfo, function (fInfo) {//onComplete callback
    var ptLot = "", ptBldgNo = "", ptValType = "", ptAnnlVal = "", ptDesc = "";
    var resultA = fInfo.features;

    if (resultA.length == 0) alert("no value");
    alert(lotno);

    content1 = "<table border='1'><tr><th><b>" + lotno + "</b></th></tr>";
    for (var i = 0; i = resultA.length; i++) {
      alert(i);
      var grpc = resultA;
      ptLot = grpc.attributes["LOT_NO_FORMATED"];
      alert(ptLot);
      content1 += "<tr><td> Valuation Type :</td><td>" + ptLot + "</td>";
      content1 += "</tr>";
    }

    content1 += "</table>";
  }, function (e) { //onError callback
    alert("Error!!!");
  });


Note all I did was copy your code and I reorganized.  I never looked at the code within to ensure that it was structured correctly.
0 Kudos
mohd_syafidabdullah
New Contributor III
I would use the already "hooked" up portion of the callback within the queryTask.execute. The usage for .execute is below

execute(parameters, callback?, errback?)

The "callback?" is where you would place your code that you have attempted to use the dojo.connect to below:

,function(fInfo){  ...etc..

You might want to try something like this instead

  qKADCMKinfo.execute(queryInfo, function (fInfo) {//onComplete callback
    var ptLot = "", ptBldgNo = "", ptValType = "", ptAnnlVal = "", ptDesc = "";
    var resultA = fInfo.features;

    if (resultA.length == 0) alert("no value");
    alert(lotno);

    content1 = "<table border='1'><tr><th><b>" + lotno + "</b></th></tr>";
    for (var i = 0; i = resultA.length; i++) {
      alert(i);
      var grpc = resultA;
      ptLot = grpc.attributes["LOT_NO_FORMATED"];
      alert(ptLot);
      content1 += "<tr><td> Valuation Type :</td><td>" + ptLot + "</td>";
      content1 += "</tr>";
    }

    content1 += "</table>";
  }, function (e) { //onError callback
    alert("Error!!!");
  });


Note all I did was copy your code and I reorganized.  I never looked at the code within to ensure that it was structured correctly.


Hi Diana,

thanks for the reply..I try to organize my code refer to your suggestion..still no luck.
FYI, the query made to the services that only contains non-spatial table(attribute table)..
is it ok?

tq
0 Kudos
DianaBenedict
Occasional Contributor III
One other thought, when you create the featureLayer for the table, did you add it to the map?  Generally what I do is the following:

1) create the Dynamic and Feature services that I need
myDynamicLayer = esri.layers.ArcGISDynamicMapServiceLayer("http://xx.xx.xx.xx:8399/arcgis/rest/services/v_pv/MapServer",{    
   id: "dynamicLayer1", 
  opacity:0.5
});


2) add all your services to the map by either using
map.addLayer(featureLayer)   OR..
map.addLayers([myDynamicLayer, myOtherService, et...)   //here you provide an array of layers to add to the map

3) connect to either map.addLayer event or map.addLayers event look at esri documentation for both examples
onLayerAddResult(layer, error)  //fires when a "specific" layer has been added
http://help.arcgis.com/en/webapi/javascript/arcgis/jsapi/#Map/onLayerAddResult
onLayersAddResult(results) //used for addLayers event
http://help.arcgis.com/en/webapi/javascript/arcgis/jsapi/#Map/onLayerAddResult
OR you can use
map.onLayerAdd   //which fires anytime a layer is added to the map

You will need to decide how you will connect this event to ensure that all your layers of interest have been added to the map. I would refer to the ESRI Editing Samples to see how they do it:
http://help.arcgis.com/en/webapi/javascript/arcgis/jssamples/#category/editing

4) call your method to return the results. 

I am assuming that your nonSpatial Table is listed as ID 9 in your MapService.
Also, based on your where clause below
queryInfo.where = "LO_NO = 0007460";

I am assuming that LO_NO field exists in your layer as indicated in your query (same spelling same casing). And, that it is an interger field?  If it is a string field then you need to change your where clause to account for the single quotes as so:
queryInfo.where = "LO_NO = '" + 0007460 + "'"; 

Good luck
0 Kudos