fakerudy

QueryTask using tokens

Discussion created by fakerudy on Oct 25, 2010
Latest reply on Apr 5, 2012 by GeorgePan
Is it possible to use a token with a single layer url in Javascript API? More specifically, with esri.tasks.QueryTask()?

For example, if I have a token:

var token = 123456

and place it at the end of a single layer url:

dynamicLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://mywebsite/ArcGIS_AD/rest/services/AD_All/Map_Service/MapServer/1?token=" + token);

it does not work.

However, in cases such as esri.layers.ArcGISDynamicMapServiceLayer, I can work around it by using:

dynamicLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://mywebsite/ArcGIS_AD/rest/services/AD_All/Map_Service/MapServer/?token=" + token);
var visibleLayers = [1];
dynamicLayer.setVisibleLayers(visibleLayers);
map.addLayer(dynamicLayer);

This works great with esri.layers.ArcGISDynamicMapServiceLayer() and esri.tasks.FindTask(), but I'm unable to find a workaround for esri.tasks.QueryTask().
It appears that I have to use the single layer url for QueryTask, which seems to be a problem when using tokens (see first example):

esri.tasks.QueryTask("http://mywebsite/ArcGIS_AD/rest/services/AD_All/Map_Service/MapServer/1");

Does anyone know of a work around for esri.tasks.QueryTask() when using tokens?

Thank you!

Outcomes