Select to view content in your preferred language

waitForJobCompletion not executing

676
1
Jump to solution
04-07-2023 10:05 AM
JasonJordan00
Frequent Contributor

Hi all, I've been working on a GP tool that will take a record and print out a PDF report on it. I'm trying to use some Javascript within an HTML embed to call the tool when a link is clicked. It will generate the report, check when the job is completed, then open the URL to the PDf in a new tab.

Its 99% working, and I can see the server generate the report in the log and can follow the Job ID and open the PDF on my own, however JobInfo in the code never seems to return a completed status to open it up in a tab. I can see it checking the status every 1.5 seconds in the server log though. Any ideas why lines 30-32 just won't go anywhere? 

 

 

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Print Abstract of Bids</title>
  <script src="https://js.arcgis.com/4.20/"></script>
  <script>
    function executeGeoprocessing() {
      var outputFileUrl;
      var params = {};
      params.contract = "10-100"; //sample record, change to variable on embed
      const url = "https://xxxxxxxx/xxxxxx/rest/services/PrepareAbstractOfBids/GPServer/Prepare%20Abstract%20of%20Bids";

      require([
        "esri/tasks/Geoprocessor",
        "esri/rest/support/JobInfo"
      ], function(Geoprocessor, JobInfo) {
        var gp = new Geoprocessor(url);
        gp.submitJob(params).then((jobInfo) => {
          const jobid = jobInfo.jobId;
          console.log("ArcGIS Server job ID: ", jobid);

          const options = {
            interval: 1500,
            statusCallback: (j) => {
              console.log("Job Status: ", j.jobStatus);
            }
          };

          jobInfo.waitForJobCompletion(options).then(() => {
            outputFileUrl = jobInfo.jobOutputInfo[0].value.url;
            window.open(outputFileUrl, "_blank");
          });
        });
      });
    }

    document.addEventListener("DOMContentLoaded", function(event) {
      var link = document.getElementById("print-abstract-link");
      link.addEventListener("click", function(event) {
        event.preventDefault();
        executeGeoprocessing();
      });
    });
  </script>
</head>
<body>
  <p><a href="#" id="print-abstract-link">Print Abstract</a></p><br>
</body>
</html>

 

 

 

0 Kudos
1 Solution

Accepted Solutions
JasonJordan00
Frequent Contributor

Mistake of my own making, changed the lines to 

          jobInfo.waitForJobCompletion(options).then(() => {
		  jobInfo.fetchResultData('outfile').then(function(result){
		  outputFileUrl = result.value.url;
		  window.open(outputFileUrl, "_blank");

 

and it works as planned. Thanks to everyone who took a look! 

View solution in original post

0 Kudos
1 Reply
JasonJordan00
Frequent Contributor

Mistake of my own making, changed the lines to 

          jobInfo.waitForJobCompletion(options).then(() => {
		  jobInfo.fetchResultData('outfile').then(function(result){
		  outputFileUrl = result.value.url;
		  window.open(outputFileUrl, "_blank");

 

and it works as planned. Thanks to everyone who took a look! 

0 Kudos