return status of GP call

502
14
Jump to solution
04-03-2020 11:34 AM
jaykapalczynski
Frequent Contributor

I cant seem to get the results of my GP call....is Synchronous call so .execute would be used.

What am I missing here?

I think I have to use the getResultData because of the Synchronous service

additionally I have an output parameter on the service...I would like to learn how to caputure this value as well

Noting that this works fine:

gpJSON.execute(params);

var HistoricUser = document.getElementById(JSONstring).value;

var params = {
      request: HistoricUser               
};

gpJSON.execute(params).then(function (jobInfo) {
                    
    var jobid = jobInfo.jobId;

    var requestOptions = {
         interval: 500,
         statusCallback: function (j) {
            console.log("Job Status: ", j.jobStatus);
         }
    };

    gpJSON.getResultData(jobId, resultName, requestOptions).then(function () {
         alert("job completed");
    });            
});‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
1 Solution

Accepted Solutions
ThanHtetAung_EsriAu
Esri Regular Contributor

Hi jay kapalczynski‌,

Well I just have a look your code.

The problem is the asp.net button postback make your form to fully reload and the gptask code is working well.

I add sample with normal html client button vs asp.net button.

And need to adjust the param call as well.

asp.net button click does not make quite noticeable on postback to reload but you can catch by date time log.

Once gptask is executed, form is reload so all the context lost and task will not execute.

Whereas client side button work smoothly.

Please take a look at the sample.

For asp.net web form, I shall suggest to use ajax manager to prevent postback, and disable postback form validation and so on.

You need to check a lot of factor.

View solution in original post

14 Replies
Noah-Sager
Esri Regular Contributor

It's difficult to say without seeing the code run, but how are you defining resultName? I think you need a string value there of the name of the result parameter. What does gpJSON look like if you add a breakpoint before the getResultData and inspect it in the console? A simple codepen or something would help troubleshoot as well.

0 Kudos
jaykapalczynski
Frequent Contributor

This works:

 gpJSON.execute(params);  

This does not:

gpJSON.execute(params).then(function (jobInfo) {

  // snip

var gpUrlJSON ="https://xxxx.gov/arcgis/rest/services/DGIF_Test/createJSON/GPServer/createJSON";
var gpJSON = new Geoprocessor(gpUrlJSON);‍‍

my return parameter is called "result"...I changed my code to this but still nothing

I dont even get into the function to return a simple alert as seen below....so something is going wrong

gpJSON.getResultData(jobId, result, requestOptions).then(function () {
alert("jobId");
});

‍‍‍‍

0 Kudos
Noah-Sager
Esri Regular Contributor

Ok, so this never works?

gpJSON.execute(params).then(function (jobInfo) {

What does gpJSON.execute(params) return?

Can you host a simplified app on codepen or somewhere that shows this? That would make it a lot easier to troubleshoot. 

0 Kudos
jaykapalczynski
Frequent Contributor

it still passes the parameter and the python script works...but it does not return anything....as I mentioned if I try and alert the jobid i get "undefined"

its in a huge app right now...trying to think of way to shrink ot down....will try and post something a bit later...

0 Kudos
jaykapalczynski
Frequent Contributor

In my code above it I alert the Jobid I get UNDEFINED

var jobid = jobInfo.jobId;
alert(jobid);
0 Kudos
ThanHtetAung_EsriAu
Esri Regular Contributor

Hi jay kapalczynski‌,

Please check your published gptask whether it is sync or async.

If sync, we shall find out more like that

gpJSON.execute(params, lang.hitch(this, function (jobInfo) {
//job submit success case
}),
function(err){
//this is in error case
console.log("I got error with job execution")
console.log(err);
}
);‍‍‍‍‍‍‍‍‍

If async, use submitJob.

gpJSON.submitJob(params, lang.hitch(this, function (jobInfo) {

   //do what you need
     gpJSON.getResultData(jobInfo.jobId, "Results", lang.hitch(this, function (result) {

//result....
});

}));

‍‍‍‍‍‍‍‍‍‍

lang is for dojo/_base/lang , better to import and use that way not to lose your this context.

And reference links

Geoprocessor | ArcGIS API for JavaScript 4.14 

Geoprocessor | API Reference | ArcGIS API for JavaScript 3.31 

jaykapalczynski
Frequent Contributor

First off when the below is run it properly sends the parameter to the GP Service and the python script behind the scenes functions properly...

BUT I am not getting anything back or anything written to the console.  I do not even get the alert to fire in the .execute function.

No errors in the console....Im puzzled.

I am definitely Synchronous

I have a .net c# webpage that I am clicking a button as you can see below.  Using a window.JSControlller to get to my JS Function.....

BUT I am now getting an error relating to the LANG which I think I have referenced correctly in the JS File...

.ASPX PAGE

<asp:Button ID="btnGISPush" runat="server" OnClientClick="window.JsController.btnGISPush_Click()" Text="GIS Push"  CausesValidation="true" /><br />
 ‍‍‍‍‍‍

ENTIRE JS PAGE

I added the requires for dojo lang....but nothing happening and no alerts from withing the function and not err going to console...hmmmmm

require(["dojo/_base/lang"], function(lang){  // lang now contains the module features});

require([
    "esri/tasks/Geoprocessor", "dojo/_base/lang"
], function (Geoprocessor, lang) {
        "use strict";

        var gpUrlJSON ="https://xxxx.gov/arcgis/rest/services/Test/createJSON/GPServer/createJSON";
        var gpJSON = new Geoprocessor(gpUrlJSON);

        window.JsController = {
            btnGISPush_Click: function () {
                // Capture String value to populate params
                var HistoricUser = document.getElementById(JSONstring).value;
                alert("Parameter being passed: " + HistoricUser);

                var params = {
                    request: HistoricUser
                };

                gpJSON.execute(params, lang.hitch(this, function (jobInfo) {
                    //job submit success case
                    var jobid = jobInfo.jobId;

                    alert("jobId stringify: " + JSON.stringify(jobid));
                    console.log("jobId: " + jobid);
                }),
                    function (err) {
                        //this is in error case
                        console.log("I got error with job execution")
                        console.log(err);
                    }
                );

            }   // END OF BUTTON CLICK FUNCTION

        };   // END OF JS CONTROLLER

}); // END OF REQUIRE‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
jaykapalczynski
Frequent Contributor

Now trying this with no success.....not one alert comes up BUT the parameter is passed properly and the python script runs successfully...no return of any kind and no error....uggggg

        window.JsController = {
            btnGISPush_Click: function () {
                // Capture String value to populate params
                var HistoricUser = document.getElementById(JSONstring).value;
                alert("Parameter being passed: " + HistoricUser);
                console.log(HistoricUser);

                var params = {
                    request: HistoricUser
                };

                gpJSON.execute(params, lang.hitch(this, function (jobInfo) {

                    var jobid = jobInfo.jobId;
                    alert("jobid: " + jobid);


                    var resultName = "result";

                    var requestOptions = {
                        interval: 500,
                        statusCallback: function (j) {
                            console.log("Job Status: ", j.jobStatus);
                        }
                    };

                    console.log("jobid: " + jobInfo.jobid + " resultName: " + resultName);
                    alert("jobid: " + jobid + " resultName: " + resultName);


                    gpJSON.checkJobStatus(jobid, requestOptions).then(function () {
                        var jobInfoValue = jobid.jobStatus;
                        alert(jobInfoValue);
                        console.log(jobInfoValue);
                        //console.log("trying to get you a value");
                        //alert(requestOptions);
                    });
                    gpJSON.getResultData(jobId, "result", lang.hitch(this, function (result) {
                        var jobid = result;
                        alert(jobid);
                        console.log(jobid);
                    }));


                }),
                    function (err) {
                        //this is in error case
                        console.log("I got error with job execution")
                        console.log(err);
                    }
                );‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
ThanHtetAung_EsriAu
Esri Regular Contributor

Hi jay kapalczynski‌,

Getting there

Check your network traffic, may be try with chrome debugger, network tab.

Does your gptask/job return any response?

0 Kudos