Select to view content in your preferred language

Running geoprocessing script from custom widget

977
4
Jump to solution
10-22-2017 10:09 PM
MarkEastwood
Frequent Contributor

Hi all,

I'm taking my first foray into creating a custom widget and am running into some difficulty. The geoprocessing script I am trying to run takes a user entry, and uses that value to create a report. I am having troubles getting the geoprocessing service to run. My script is below:

  


  define([
"dojo/_base/declare",
"jimu/BaseWidget",
"dijit/_WidgetsInTemplateMixin",
"dojo/aspect",
"jimu/ConfigManager",
'dojo/_base/html',
"jimu/WidgetManager",
"esri/layers/FeatureLayer",
"dojo/query",
"esri/tasks/query",
"esri/tasks/QueryTask",
"dojo/store/Memory",
"dojo/_base/array",
"dojo/on",
"dojo/_base/lang",
"dijit/form/ComboBox",
"dojo/dom",
'jimu/dijit/Message',
'esri/tasks/GPMessage',
'esri/tasks/JobInfo',
'esri/request',
"esri/tasks/Geoprocessor"
],

function (
declare,
BaseWidget,
_WidgetsInTemplateMixin,
aspect,
html,
ConfigManager,
WidgetManager,
FeatureLayer,
dojoQuery,
Query,
QueryTask,
Memory,
array,
on,
lang,
dom,
JobInfo,
esriRequest,
Geoprocessor,
GPMessage,
Message
) {
return declare([BaseWidget, _WidgetsInTemplateMixin], {

baseClass: "jimu-widget-reportingtool",

queryTask: null,
query: null,
userEntry: null,
gp: null,

postCreate: function () {
this.queryTask = new QueryTask("myservice");
this.query = new Query();
this.query.returnGeometry = false;
this.query.outFields = ["bridge_name_num"];
this.query.where = "bridge_name_num <> '' AND status <> 'Undefined'";
},

onOpen: function () {
this.queryTask.execute(this.query, lang.hitch(this, this.populateList));
},

populateList: function (results) {
//Populate the ComboBox with unique values
var zone;
var values = [];
var testVals = {};

//Add option to display all zoning types to the ComboBox
values.push({
name: "ALL"
});

//Loop through the QueryTask results and populate an array
//with the unique values
var features = results.features;
array.forEach(features, function (feature) {
zone = feature.attributes.bridge_name_num;
if (!testVals[zone]) {
testVals[zone] = true;
values.push({
name: zone
});
}
});
//Create a ItemFileReadStore and use it for the
//ComboBox's data source
var dataItems = {
identifier: "name",
label: "name",
items: values
};
//console.log(dataItems);
var store = new Memory({
data: dataItems
});
//console.log(store);
this.mySelect.set("store", store);
},

exportReport: function(){
//this.results.innerHTML = "<center><b>Processing...</b><br><img src='widgets/tExport/images/loading.gif' width='360px'></center>"


var userEntry = this.mySelect.value;

//var message = new Message({
//message: userEntry,
//titleLabel: "userEntry"
//});

this.gpSubmit(this.mySelect.value);
},

gpSubmit: function(userEntry){

this.gp = new Geoprocessor(myservice");

var params = {
"Bridge_Name": userEntry
}
console.log(params);
this.gp.submitJob(params, lang.hitch(this,this.jobComplete), this.jobStatus, lang.hitch(this, this.jobError));
},

jobComplete: function(jobInfo){

this.gp.getResultData(jobInfo.jobId, "pdf_export", lang.hitch(this, function(data){
console.log(data);
console.log(this.results);

this.results.innerHTML = "<a href='" + data.value.url + "'><div><img src='widgets/VegtExport/images/zip-icon.jpg' height='20px'>  <b>Export Package Ready!</b></div></a>";

}));
console.log(jobInfo.jobStatus);
console.log(jobInfo.results);

},
jobStatus: function(jobInfo){

console.log(jobInfo);

},
jobError: function(error){

this.results.innerHTML = "<center><b>Export Failed...</b></center>";

}
});
});

At the moment the error I am getting is:

Uncaught TypeError: this.gp.submitJob is not a function
at Object.gpSubmit (Widget.js?wab_dv=2.6:131)
at Object.exportReport (Widget.js?wab_dv=2.6:120)
at HTMLDivElement.<anonymous> (init.js:63)

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

ME,

   You are correct I had it backwards. You have your requires and there subsequent parameter names out of sequence:

define([ 
"dojo/_base/declare", 
"jimu/BaseWidget", 
"dijit/_WidgetsInTemplateMixin", 
"dojo/aspect", 
"jimu/ConfigManager",
'dojo/_base/html',
"jimu/WidgetManager", 
"esri/layers/FeatureLayer", 
"dojo/query", 
"esri/tasks/query", 
"esri/tasks/QueryTask", 
"dojo/store/Memory", 
"dojo/_base/array", 
"dojo/on", 
"dojo/_base/lang",
"dijit/form/ComboBox",
"dojo/dom",
'jimu/dijit/Message',
'esri/tasks/GPMessage',
'esri/tasks/JobInfo',
'esri/request',
"esri/tasks/Geoprocessor"
], 

function ( 
declare, 
BaseWidget, 
_WidgetsInTemplateMixin, 
aspect, 
html,
ConfigManager, 
WidgetManager, 
FeatureLayer, 
dojoQuery, 
Query, 
QueryTask, 
Memory, 
array, 
on, 
lang,
dom,
JobInfo,
esriRequest,
Geoprocessor,
GPMessage,
Message
) { 

Line 6 does not match line 31 and that throws all your other parameters out of line.

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Emeritus

ME,


  Is your GP service synchronous or asynchronous? GP submit is only available for synchronous and execute is what you use for asynchronous.

0 Kudos
MarkEastwood
Frequent Contributor

The GP service is asynchronus. I thought GP Submit was meant for asynchronus services based on my reading here.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

ME,

   You are correct I had it backwards. You have your requires and there subsequent parameter names out of sequence:

define([ 
"dojo/_base/declare", 
"jimu/BaseWidget", 
"dijit/_WidgetsInTemplateMixin", 
"dojo/aspect", 
"jimu/ConfigManager",
'dojo/_base/html',
"jimu/WidgetManager", 
"esri/layers/FeatureLayer", 
"dojo/query", 
"esri/tasks/query", 
"esri/tasks/QueryTask", 
"dojo/store/Memory", 
"dojo/_base/array", 
"dojo/on", 
"dojo/_base/lang",
"dijit/form/ComboBox",
"dojo/dom",
'jimu/dijit/Message',
'esri/tasks/GPMessage',
'esri/tasks/JobInfo',
'esri/request',
"esri/tasks/Geoprocessor"
], 

function ( 
declare, 
BaseWidget, 
_WidgetsInTemplateMixin, 
aspect, 
html,
ConfigManager, 
WidgetManager, 
FeatureLayer, 
dojoQuery, 
Query, 
QueryTask, 
Memory, 
array, 
on, 
lang,
dom,
JobInfo,
esriRequest,
Geoprocessor,
GPMessage,
Message
) { 

Line 6 does not match line 31 and that throws all your other parameters out of line.

MarkEastwood
Frequent Contributor

Ah, of course .... Thanks!

0 Kudos