Call & pass parameters to GP Service

218
2
Jump to solution
03-31-2020 10:04 AM
jaykapalczynski
Frequent Contributor

I have a python script that works great.

I created a tool in a toolbox and point to the python script and this runs great.

I then run the tool again and publish it to a service.

From the service I add my parameter (see below) and it runs great.

SO far so good.

Now from JavaScript I do the following (see below code at bottom). 

But this time it does not accept the parameter it keeps using the default value that was created on the service after I published it. 

To publish the service I am right clicking the result in ArcMap and using that to publish

1. I cannot figure out how to remove the default value

2. I cannot figure out  how to run the tool without adding a parameter before I publish it to ArcGIS Server

3. I cannot figure out how to over write the default value from JavaScript...

If I copy the string I am trying to use in Javascript and paste it in the GPService in ArcGIS Server it runs FINE.

BUT using the same string and calling the SAME ArcGIS Service from JavaScript it uses the default value that was created when it was published to ArcGIS Server.

I  can copy the below string DIRECTLY from the code below without the ; at the end and it works fine in the GP Service

{"employees": [{ "address": "1520 Split Oak Ln, Henrico, Virginia, 23229", "distance": "10", "id": "1" }, { "address": "113 Buffalo Rd, Clarksville, Virginia(VA), 23927", "distance": "50", "id": "4" }, { "address": "8817 Sherando Dr, Bristow, Virginia(VA), 20136", "distance": "20", "id": "5" }]}

Is it the default value?

Is it how I am pushing the parameter to the Service?

Something else?

I hope that makes sense.  Thoughts????

var gpUrlJSON = "https://vvvvvv.gov/arcgis/rest/services/Test/GeometryJSON/GPServer/createJSON";

var gpJSON = new Geoprocessor(gpUrlJSON);



// SNIP

var dictstring = {"employees": [{ "address": "1520 Split Oak Ln, Henrico, Virginia, 23229", "distance": "10", "id": "1" }, { "address": "113 Buffalo Rd, Clarksville, Virginia(VA), 23927", "distance": "50", "id": "4" }, { "address": "8817 Sherando Dr, Bristow, Virginia(VA), 20136", "distance": "20", "id": "5" }]};
            
dictstringtoPass = dictstring;

gpJSON.execute(dictstringtoPass);
0 Kudos
1 Solution

Accepted Solutions
jaykapalczynski
Frequent Contributor

I feel so embarrassed....I wasnt creating the params correctly...I was never calling the parameter by its name so it just used the default.

Where "request" was the name of the input parameter as seen in my original post

var dictstring = {"employees": [{ "address": "1520 Split Oak Ln, Henrico, Virginia, 23229", "distance": "10", "id": "1" }, { "address": "113 Buffalo Rd, Clarksville, Virginia(VA), 23927", "distance": "50", "id": "4" }, { "address": "8817 Sherando Dr, Bristow, Virginia(VA), 20136", "distance": "20", "id": "5" }]};
            
dictstringtoPass = dictstring;
gpJSON.execute(dictstringtoPass);

var params = {
    request: dictstring
};

gpJSON.execute(params);

View solution in original post

0 Kudos
2 Replies
jaykapalczynski
Frequent Contributor

any ideas what could be happening?  

0 Kudos
jaykapalczynski
Frequent Contributor

I feel so embarrassed....I wasnt creating the params correctly...I was never calling the parameter by its name so it just used the default.

Where "request" was the name of the input parameter as seen in my original post

var dictstring = {"employees": [{ "address": "1520 Split Oak Ln, Henrico, Virginia, 23229", "distance": "10", "id": "1" }, { "address": "113 Buffalo Rd, Clarksville, Virginia(VA), 23927", "distance": "50", "id": "4" }, { "address": "8817 Sherando Dr, Bristow, Virginia(VA), 20136", "distance": "20", "id": "5" }]};
            
dictstringtoPass = dictstring;
gpJSON.execute(dictstringtoPass);

var params = {
    request: dictstring
};

gpJSON.execute(params);
0 Kudos