Submit job to GP Service and use string input, not default value?

917
1
Jump to solution
04-02-2018 06:51 AM
MKF62
by
Occasional Contributor III

I'm having issues submitting string input to a GP Service. Using AGS 10.4.1. The service has one input parameter of string type, but every time I run the service it runs it with the default string input rather than the value I am passing to the GP Service. How do you get it to accept your new string input? I'm calling the service from Javascript API 3.23. I upload a zip file and accept string input from a form element:

<form id="uploadForm" method="post" enctype="multipart/form-data">
      State Abbreviation: <input type="text" name="stateAbbrev" id="stateAbbrev"><br>
      <label class="custom-file-upload"><input type="file" name="file" id="dataUpload"/>File Upload</label>     
      <input type="button" value="Upload" id="upload"/>
</form>

Then, after clicking the upload button, it gets to this function:

function uploadSucceeded(response) {
      var itemID = response["item"].itemID;
      var dataFile = new esri.tasks.DataFile();
      dataFile.itemID = itemID;
      var stateAbbrv = document.getElementById("stateAbbrev").value;
      console.log("File upload successful");
      var params = {"Input_Zip_File": dataFile, "State_Abbreviation": stateAbbrv};
      console.log('Input parameters: '+ dojo.toJson(params));
      gp.submitJob(params, gpJobComplete, gpJobStatus, function(error){
        console.error(error.jobStatus + '(' + error.jobId + '):' + dojo.toJson(error));
      });
    }

In the function above, the line

var params = {"Input_Zip_File": dataFile, "State_Abbreviation": stateAbbrv};

sets the State_Abbreviation parameter to the new user-supplied string input. This prints out correctly in the browser console:

Input parameters: {"Input_Zip_File":{"itemID":"i0cd7358b-f7d4-4238-8d10-4bbdc624e895"},"State_Abbreviation":"AR"}

But, using messages in the browser console, I can see it's running the GP Service using the default string input of "TN" which is the value the GP Service was published with (thus it becomes the default value). I need to somehow override that value, but I can't figure out how?

0 Kudos
1 Solution

Accepted Solutions
MKF62
by
Occasional Contributor III

Check your spelling kids... I looked at my input parameters in the service directory and found a spelling mistake that caused this issue. In my Javascript, I set the input parameter "State_Abbreviation" when in my service directory it was mispelled "State_Abbrevation". All fixed now.

I'll leave the post up since it's a good example of how to input parameters into a geoprocessing service using Javascript API.

View solution in original post

1 Reply
MKF62
by
Occasional Contributor III

Check your spelling kids... I looked at my input parameters in the service directory and found a spelling mistake that caused this issue. In my Javascript, I set the input parameter "State_Abbreviation" when in my service directory it was mispelled "State_Abbrevation". All fixed now.

I'll leave the post up since it's a good example of how to input parameters into a geoprocessing service using Javascript API.