2

I have an ESRI Javascript application that uses a geoprocessing service that uses a cutsom GP tool. Since I have a set of values to be passed to the GP service I am planning to pass in it as a record set instead of string values. These are just attributes and no geometry associated with it. I think I can use FeatureSet in Javascript to pass GP input parameters.

Something like this. Let me know if this is the right way to pass record sets. I will have several records.

var attr = {"OBJETID:1", "Name":"Test", "Address:"Value2"};
var graphic = new esri.Graphic(null,null,attr,null);
var features= [];
features.push(graphic);
var featureSet = new esri.tasks.FeatureSet();
featureSet.features = features;

Now inside the custom GP function tool how do I set the paramaters to read the input? Following is what I am trying to do. Is this the correct approach?

IGPParameterEdit gpParameterEdit = new GPParameterClass(); 
IGPDataType gpDataType = new GPRecordSetTypeClass();// GPStringTypeClass();
IGPValue gpValue = new GPRecordSetClass();// GPStringClass(); ; 
gpParameterEdit.Name = "legal_desc";
gpParameterEdit.DisplayName = "Legal Description";
gpParameterEdit.DataType = gpDataType;
gpParameterEdit.Value = gpValue;
gpParameterEdit.Direction = esriGPParameterDirection.esriGPParameterDirectionInput;
gpParameterEdit.ParameterType = esriGPParameterType.esriGPParameterTypeRequired;

Then while Casting the value, How do I cast and read the values from the input featureset? Following is what I am trying to do and it is returning null for gpRecordSet.

IGPValue gpValue = parameterValueArray.GetGPValue(_parameterIndex);
IGPRecordSet gpRecordSet = (IGPRecordSet)gpValue;

Basically I am trying to see how to pass in set of attributes from JavaScript and read it in custom GP Tool.

Now the return value I expect in the JavaScript application is a polygon graphic and no attributes. What is the best way to return the polygon? What I understand from my research is that I need to create in-memory featurecalss and return the polygon as feature. Is there a better way.

All help appreciated.

1
  • Please use code sample (ctrl+K) to insert your code. Are you using ArcGIS Java Script API ??
    – Sunil
    Feb 5, 2013 at 5:12

1 Answer 1

2

You are going about in the wrong way. Each input is a different parameter of the type string, and you should keep it as that.

Often the simplest option is the best option. Make your model/tool have as many parameters as you require. Make sure that you can run it within ArcGIS desktop. Only then should you publish it as a geoporcessing service. Once it is published, make sure that you run it from the REST endpoint as well as by consuming the gp service within ArcGIS Desktop.

Now it is very easy to consume it within your JavaScript Application.

So if your geoprocessing service takes two inputs say Name & Address, then it is very easy to call it like this:

var params = {"Name":"Test", "Address:"Value2"};
//assuming you have initialized the gp beforehand       
gp.submitJob(params, completeCallback , statusCallback,errorCallback);

There is absolutely no reason or need to wrap the two parameters as attributes of a graphic, and then unwrap them inside your custom GP tool.

Update After looking at your comment, that you have five fields, each can have five or more string, I want to expand on my Answer.

You should always look at doing things in the standard way, because that is the simplest way to make sure that it will work. So if you have 5 parameters, each of which can take multiple values, you need to make each of this parameter a MultiValue.

Please have a look at this page which talks about the supported datatypes in ArcGIS Server

Firstly, this data type will be defined in your model, which contains your custom Geoprocessing tool. If you want your tool to consume these MultiValue parameters, your tool should use GPMultiValue object while making the parameter Array

3
  • This was an example that I was showing. I have a lot of data to pass. What I showed you here is a concept of it. I have four parameters to pass each parameter will have multiple records around 5 to 10 records in each one. I can pass it as very long strings. But I thought it will be easier and better if I create recordset. On the server also it will be easy to read the record set. What I would like to know is if we can pass these values as FeatureSet, then how do we define the parameters in the custom GP Tool. Also what is the best way to get a single polygon graphic back to client.
    – Cyril
    Feb 5, 2013 at 14:31
  • @Cyril: I have updated my answer Feb 5, 2013 at 16:25
  • Thanks Devdatta, I see that for my requirements it is better to use the Featureset. Basically I would like to do something similar to the following example from ESRI. The Javascript part I understand. I am looking for some help with defining input and output parameters in custom GP tool similar to the example below. Also how the parameters are UnPacked and Packed in the custom tool. I am writing the tool in .NET. resources.esri.com/help/9.3/arcgisserver/apis/javascript/arcgis/…
    – Cyril
    Feb 6, 2013 at 6:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.