Run GP Tool from JavaScript

11-30-2021 06:55 AM
Frequent Contributor

I have an existing Publish GP Tool that accepts a couple Parameters.  It does its thing and then passes back some results.  Something is going on and I want to rewrite this persons code but before doing so I want to make sure I am doing this the most logical way.  


The Current project is using API 4.13



Execution Type: esriExecutionTypeSynchronous

Supported Operations:   Execute Task

 CREDENTIALS - I need to add to this a Token that the service will require as its secured. How do I add the token

BELOW are the params I am looking to send

NOTING - I need to use the EXECUTE not SUBMIT as that is what the service requires


Can someone help with an example to show me the correct syntax etc to CALL and then grab the RESULTS and simply put in an ALERT box????

            let params = {
                "site": FeatureSet.fromJSON(
                        "geometryType": geometryType9,
                        "spatialReference": { "wkid": 102100 },
                        "features": [
                                "attributes": {
                                    "OBJECTID": 0
                                "geometry": geometry9
                "Buffer_Distance": LinearUnit.fromJSON({
                    "distance": xxx.Session.searchRequestTextbox.bufferDistance,
                    "units": "miles"
                "user": UserRole,
                "Report_Type": xxxx.Session.searchRequestTextbox.reportType



0 Kudos
3 Replies
Frequent Contributor

If you're using 4.13, you can use the Geoprocessor task. In current releases, it is deprecated in favor of the if the rest methods here.

Frequent Contributor

Does the later have an actual example....I dont think you can just write execute(xxx,xxx,xxx)

0 Kudos
Frequent Contributor

The samples for 4.13 are no longer available.

This sample is still using the GP Task

Here is a sample using the task in 3.x, it's very similar to how you would do it in 4.13 to get another look.