Select to view content in your preferred language

Using GP Service with JS API

3515
3
05-17-2011 06:54 AM
Stefan_Arndt
Esri Contributor
Hi,

i'm trying to use the JavaScript API to process a Geoprocessing Service. This Service works fine with the ArcGIS Server WebApplication. Now i want to use it with JS. The GP Service needs a Shapefile as Input Parameter.

So i read the Webhelp, the JS API Concepts and had a look at the Esri Samples. Then i tried to implement it. First like the samples, then in a more easy way with less code (just the basics).
But in no Case the Service is used.

I'm not very experienced with JavaScript, so probably there is a mistake in my Code. Perhaps in the Structure or with the Parameters. I attached the simple basic-Code with just one button to this Thread. Can anybody please have a lokk at it and check if everything is ok?

Because i'm not 100% sure if the service needs a Shapefile or a String to the Shapefile, i tried several opportunities.

var inputLayer = "http://wk2658/ArcGIS/rest/services/scotturb/FeatureServer/0";
var inputLayer = "C:\arcgisserver\scotturb\scotturb_lines_ida_half_test.shp";
var inputLayer = new esri.layers.FeatureLayer("http://wk2658/ArcGIS/rest/services/scotturb/FeatureServer/0");
var inputLayer = new esri.layers.FeatureLayer("C:\arcgisserver\scotturb\scotturb_lines_ida_half_test.shp");


I'm using:
ArcGIS Server 10 SP2 .NET Framework
Read/Write Permissions are correct i think.
0 Kudos
3 Replies
KenDoman
Frequent Contributor
According to the api reference for geoprocessing at http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/geoprocessor.htm, gp.submitJob() takes a json object for the input Parameter.
Try something like this:
var param = {inputLayer: "C:\arcgisserver\scotturb\scotturb_lines_ida_half_test.shp"}
var gp = new esri.tasks.Geoprocessor("http://wk2658/ArcGIS/rest/services/GP/GP/GPServer/server_schematic_model");
gp.submitJob(param);


Check your gp's input parameters and use those names when setting your parameter object.
0 Kudos
Stefan_Arndt
Esri Contributor
Hey kdoman,

thank you for your answer. I think you're right! So i read the Geoprocessing Class Documentation again and edited my code, as you suggested.
And i found out that "dojo.require("esri.tasks.gp");" was also missing.

But it's still not working.
The integrated alert function (just to see if it works) occurs, so the function is called

I attached the new code and 3 Pictures.
15.png shows the screen, when i start running the Model in ArcMap and insert the Path to the Databse -> It works.
16.png shows the Properties of the Model, which shows that a FeatureLayer is required as an input Parameter.
17.png shows the ArcGIS Services Directory (REST) with the supported operation "SubmitJob". Additionally there is a Choice List as Input (the Layers of the Map Document), but when i choose another one in ArcMap Desktop this still works.

Someone any other ideas?
0 Kudos
Stefan_Arndt
Esri Contributor
Entering the URL in the "http://<localhost>/ArcGIS/rest/services/<servicename>/GPServer/<GP-Service>/submitJob" like in the attached 18.png works perfectly.

Where is the difference to this code? should it not be the same?
dojo.require("esri.tasks.gp");

  var param = {inputLayer: "C:\arcgisserver\scotturb\scotturb_lines_ida_half_test.shp"}
  var gp = new esri.tasks.Geoprocessor("http://wk2658/ArcGIS/rest/services/GP/GP/GPServer/server_schematic_model");
 
   function generateDiagram() {      
  gp.submitJob(param); 
   } 


And i also tried "GPString" and "url" instead of "inputLayer"
0 Kudos