Select to view content in your preferred language

Create GPRecorset as an input to GP Task?

2676
9
Jump to solution
08-08-2012 07:16 AM
AnnCrystal
Emerging Contributor
Good morning:

Can anybody guide me how to create a GPRecorset  which pulls Address and Zipcode from two textboxes and pass it to my gp task? I couldn't find any helpful sample to do that. Please find the details of tool parameter below:-

---------------------------------------------
Parameter: Input_Table
Data Type: GPRecordSet
Display Name: Input Table
Direction: esriGPParameterDirectionInput
Default Value:
Fields:
OBJECTID (Type: esriFieldTypeOID, Alias: OBJECTID)
STANDARD (Type: esriFieldTypeString, Alias: STANDARD)
ZIPCODE (Type: esriFieldTypeString, Alias: ZIPCODE)
Parameter Type: esriGPParameterTypeRequired
-------------------------------------------------------

Thanks in advance
Ann
0 Kudos
1 Solution

Accepted Solutions
JohnGravois
Deactivated User
i took a look at the information you posted about the GP service above and perhaps you need to be passing an ObjectID as well?  if you hit a wall, i highly recommend testing directly in REST until you can figure out exactly what JSON is expected/required to run the service.  its a lot easier to reverse engineer in your Javascript application than it is to discover what REST is looking for.

the link below is related to a geocoding task rather than geoprocessing task, but it gives an example of the json for a recordset which has no geometry.
http://resources.arcgis.com/en/help/rest/apiref/geocodeaddresses.html

View solution in original post

0 Kudos
9 Replies
JohnGravois
Deactivated User
If you only want to geocode a single address it would probably be more appropriate to work with a geocoding service instead and pass the parameters directly (instead of trying to build a recordset for a geoprocessing service which expects an input table and does batch geocoding.)

The sample linked below demonstrates how to pass a value from a textbox control to an address locator which takes a single line input.  You could modify it to pull values from several textboxes and assign them to an address and zipcode field instead.

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/locator_address.html

Here is a link to the geocoding service being used.  I often find it helpful to compare and contrast behavior between geocoding services directly in REST when I see problems in my applications.

http://tasks.arcgis.com/ArcGIS/rest/services/WorldLocator/GeocodeServer
0 Kudos
AnnCrystal
Emerging Contributor
Thanks John for your reply. The model was doing more than geocoding with some intersect to pull values from other layers and so on. That's why I figured that it could be better if I stuff everything in the model.

Since, I couldn't find any js samples for implementing gprecordset, I am still confused. Can you help me with how to do create a GPRecorset which pulls Address and Zipcode from two textboxes and pass it to my gp task ?
Thanks again
Ann
0 Kudos
JohnGravois
Deactivated User
I've never tried creating and populating a RecordSet which includes attribute values only, but you should definitely be able to.

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/featureset.htm

here is a really stripped down example of passing attributes to a graphic and then storing the graphic in a recordset
//populate your attributes using name value pairs
var attr = {"Plant":"Mesa Mint", "Field2:"Value2"};
//graphics doesn't require geometry, symbology or an info window, so you can just pass in attributes
var graphic = new esri.Graphic(null,null,attr,null);

//create an empty array
var features= [];

//push in your attributes
features.push(graphic);

//create your featureSet and push in the feature
var featureSet = new esri.tasks.FeatureSet();
featureSet.features = features;


as an alternative, since many tasks actually return a recordset, it might also make sense to seperate the geocoding from the rest of your geoprocessing and pass the result from the first rather than creating the recordset from scratch.

good luck with the project.
0 Kudos
AnnCrystal
Emerging Contributor


as an alternative, since many tasks actually return a recordset, it might also make sense to seperate the geocoding from the rest of your geoprocessing and pass the result from the first rather than creating the recordset from scratch.



Thanks John for that code. Now I know to implement a GPRecordset. It runs-but won't geocode properly. I need to dig deeper for that part.
As you mentioned of using a geocoding service to geocode address and input the result to the model, I am confused about how to access that output recordset. Can you guide me with some sample for that?

Thanks again for your support.
Ann
0 Kudos
JohnGrayson
Esri Regular Contributor
Ann,
[INDENT]make sure to use version 3.1 of the JS API as the issue mentioned below was fixed at 3.1 and might cause some problems for your particular workflow:[/INDENT]


  NIM083266: esri.tasks.FeatureSet.toJson() should ignore the featureSet's fields property when it is an empty array.

John
0 Kudos
JohnGravois
Deactivated User
the first link that i posted is an excellent example of what is returned by a request to geocode a single address (a recordset of AddressCandidates)

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/addresscandidate.htm

Typically we loop through the results of a query operation or a geocoding operation and add the results to a graphics collection to draw them on the map, but in your case you would want to pass the results to a GP task which expects a recordset input.

I added an attachment which shows what you get when you interrogate the candidates variable after setting a breakpoint in the application.  If your GP service isn't expecting all those properties, you may have some additional work on your hands to remove them using a technique like delete(candidates.score);  Not to mention the fact that the attributes aren't going to be prepopulated with the exact name value pairs you need.

all in all, it may not prove to be a shortcut setting thing up this way.
0 Kudos
AnnCrystal
Emerging Contributor
Ann,
[INDENT]make sure to use version 3.1 of the JS API as the issue mentioned below was fixed at 3.1 and might cause some problems for your particular workflow:[/INDENT]


  NIM083266: esri.tasks.FeatureSet.toJson() should ignore the featureSet's fields property when it is an empty array.

John


Thanks John. Yes, I am using 3.1. This is the function which triggers on the button click:
-------------------------------------------------------------------
function findAddress(){
        
      gp = new esri.tasks.Geoprocessor("http://psc-gis-1/AGServer/rest/services/Tools/GeocodeAddress/GPServer/Geocode%20Address");
      gp.setOutSpatialReference({wkid:4326});
      var attr={"STANDARD":dijit.byId("address"), "ZIPCODE":dijit.byId("zipcode")};
   
      var graphic = new esri.Graphic(null,null,attr,null);

      var features=[];
      features.push(graphic);

       var featureSet=new esri.tasks.FeatureSet();
       featureSet.features=features;

       var params= {"Input_Table":featureSet}
       esri.show(progress);
  
        gp.submitJob(params, completeCallback , statusCallback,function(error){
          alert(error);
          esri.hide(progress);
        });
        
    }


I am also attaching the fullcode page as a zip file. Can you please take a look and tell me where i am wrong?
Thanks in advance
Ann
0 Kudos
JohnGravois
Deactivated User
i took a look at the information you posted about the GP service above and perhaps you need to be passing an ObjectID as well?  if you hit a wall, i highly recommend testing directly in REST until you can figure out exactly what JSON is expected/required to run the service.  its a lot easier to reverse engineer in your Javascript application than it is to discover what REST is looking for.

the link below is related to a geocoding task rather than geoprocessing task, but it gives an example of the json for a recordset which has no geometry.
http://resources.arcgis.com/en/help/rest/apiref/geocodeaddresses.html
0 Kudos
AnnCrystal
Emerging Contributor
i took a look at the information you posted about the GP service above and perhaps you need to be passing an ObjectID as well?  if you hit a wall, i highly recommend testing directly in REST until you can figure out exactly what JSON is expected/required to run the service.  its a lot easier to reverse engineer in your Javascript application than it is to discover what REST is looking for.

the link below is related to a geocoding task rather than geoprocessing task, but it gives an example of the json for a recordset which has no geometry.
http://resources.arcgis.com/en/help/rest/apiref/geocodeaddresses.html


Thanks John. I got it resolved. It was a simple mistake which I overlooked in getting values from the textbox. I forgot to add .get("value").
Thanks again for your support!
0 Kudos