querying image service from javascript client

Discussion created by tsmith@agi.com on Apr 17, 2012
I need to query my Image Service to find the appropriate rasterDataSet to add to my map.  To do this, I am currently making 2 sequential calls to my image service:

  1. The 1st call is to query the service to get to appropriate ObjectID of my raster dataset (where Name='someFileName')

  2. The 2nd call is to get the image

Is there anyway I can do the query and return the image all in 1 REST call?

Here is my code snippet:
     "http://<my server name>/ArcGIS/rest/services/<my image service name>/ImageServer/query?objectIds=&where=Name%3D%27" + fileName + "%27&returnGeometry=false&returnIdsOnly=true&f=pjson&callback=?",
  imageObjectID = Object.objectIds[0];
  for (var j = 0, jl = map.layerIds.length; j < jl; j++) {
              var currentLayer = map.getLayer(map.layerIds[j]);
   if (currentLayer.declaredClass == "esri.layers.ArcGISImageServiceLayer") {

  if(typeof imageObjectID != 'undefined')
       var imageServiceLayer = new esri.layers.ArcGISImageServiceLayer("http://<my server name>/ArcGIS/rest/services/<my image service name>/ImageServer/" + imageObjectID + "/image?bbox=-<SomeBoundingBox>&format=png&pixelType=U8&noData=noData%3D0&interpolation=RSP_BilinearInterpolation", { "opacity": .50 });