Select to view content in your preferred language

How do I auto-execute a geoprocessing widget?

5319
13
07-27-2015 02:15 PM
BrandonKeinath1
Deactivated User

I have a geoprocessing service that executes a reconcile and then a post of a version inside a web appbuilder application running on our ArcGIS Server.  There isn't an input but the user still has to click the "Execute" button in the geoprocessing widget.  Is there a way for them to click on the widget and have it fire the geoprocessing service? 

And if that first part is possible is it also possible to display a message box when the process completes? 

Any thoughts are appreciated.

Thanks,

Brandon

0 Kudos
13 Replies
BrandonKeinath1
Deactivated User

Replying to bring this back up in the feeds.  I am still in need of help on this topic.  Any thoughts would be appreciated.

Brandon

0 Kudos
PrevinWong1
Esri Contributor

Are you running a WAB developer version or an exported template version on your ArcGIS Server?  If so, you could just modify the widget and chain the event states of the widgets (post create, startup, call GP) so that there is minimal user interaction.  Just show a dijit message box once the GP has finished.

BrandonKeinath1
Deactivated User

Hi Previn,

We are running WAB developer edition.  I haven't worked with event states before; do you have an example you might be able to walk me through or point me to to accomplish the process you describe?

Thanks,


Brandon

0 Kudos
PrevinWong1
Esri Contributor

This widget seems to only have just the startup function so that is the only event state we have to deal with.

If you go into your WAB install folder/client/stemapp/widgets/geoprocessing.  If you open the Widget.js file in your text editor of choice.  You will notice on line 49, there is "startup: function()".  This function ends around line 129.

If you open the widget.html file, you will see around line 12, the button that calls "_onExecuteClick".  You just need to add this function to the end of the startup function so that it fires off without any user interaction.

The startup function, with the change, would look like the following with the call to execute the GP at the end.

    startup: function(){
      this.inherited(arguments);


      if(!this.config.taskUrl){
        html.setStyle(this.toolNode, 'display', 'none');
        html.setStyle(this.errorNode, 'display', '');
        return;
      }
      this.inputNodes = [];
      this.drawTools = [];


      //each result will be displayed by dijit
      this.resultNodes = [];
      this.resultLayers = [];


      editorManager.setMap(this.map);
      editorManager.setNls(this.nls);


      resultRendererManager.setMap(this.map);
      resultRendererManager.setNls(this.nls);


      this.gp = new Geoprocessor(this.config.taskUrl);
      this.gp.setOutSpatialReference(this.map.spatialReference);


      if(this.config.updateDelay){
        this.gp.setUpdateDelay(this.config.updateDelay);
      }


      this.tab = new TabContainer({
        tabs: [{
          title: this.nls.input,
          content: this.inputPaneNode
        }, {
          title: this.nls.output,
          content: this.outputPaneNode
        }],
        selected: this.nls.input
      });
      this.tab.placeAt(this.domNode);
      this.tab.startup();


      this.loading = new LoadingIndicator({
        hidden: true
      }, this.loadingNode);
      this.loading.startup();


      //Fires when a synchronous GP task is completed
      this.own(on(this.gp, 'execute-complete', lang.hitch(this, this.onExecuteComplete)));


      //Fires when an asynchronous GP task using submitJob is complete.
      this.own(on(this.gp, 'job-complete', lang.hitch(this, this.onJobComplete)));


      this.own(on(this.gp, 'job-cancel', lang.hitch(this, this.onJonCancel)));


      //Fires when a job status update is available.
      this.own(on(this.gp, 'status-update', lang.hitch(this, this.onStatusUpdate)));


      //Fires when the result of an asynchronous GP task execution is available.
      this.own(on(this.gp, 'get-result-data-complete',
        lang.hitch(this, this.onGetResultDataComplate)));


      //Fires when a map image is generated by invoking the getResultImage method.
      this.own(on(this.gp, 'get-result-image-layer-complete',
        lang.hitch(this, this.onGetResultImageLayerComplate)));


      this.own(on(this.gp, 'error', lang.hitch(this, this.onError)));


      html.setAttr(this.helpLinkNode, 'href', this.config.helpUrl);


      this._generateUniqueID();
      if(!("serverInfo" in this.config)){
        //Load gp server info if it does not exist.
        gputils.getServiceDescription(this.config.taskUrl).then(lang.hitch(this,
          function(taskInfo){
          this.config.serverInfo = taskInfo.serverInfo;
          this._createInputNodes();
        }));
      }else{
        this._createInputNodes();
      }
      
      this._onExecuteClick();
    },
BrandonKeinath1
Deactivated User

Hi Previn,

I don't think I'm doing something right.  When I use your code for the startup function I still need to interact with the input dialog.  It also seems to change the input dialog for all my geoprocessing widgets; some of which do require some user input parameters.  Ideally I would like the user to click the widget and then a few seconds later receive a message box or some other visual cue that the process has completed (please forgive my terrible mark-up).

allgoodbox.JPG

Thanks,

Brandon

0 Kudos
PrevinWong1
Esri Contributor

Brandon,

Yes, making that change will clause all other GP tools to auto execute.  What you want to you is make a copy of the GP widget by copying the folder, call the folder something else, and change value in the "name" in the manifest.json file and the "_widgetLabel" in the nls/string.js file.  Best to change it to match the folder name.  That way WAB will see it as a whole different widget.  Then you can have this one auto execute, and then use the existing GP widget for all other GP needs.

I made a simple GP that doesn't take any user inputs and using the code change above, does auto fire and complete.  Please check the video attached.

BrandonKeinath1
Deactivated User

Hi Previn,

You're video looks great and thank you for all the help.  I'm sorry to be so dense but it still isn't auto-executing for me.  I'll review my steps.

1. I copied the geoprocessing widget from my widgets folder and renamed it Geoprocessing_autoexec

2. I modified "name" in the manifest.json file in the new "Geoprocessing_autoexec" widget to be "Geoprocessing_autoexec"

3.  I modified _widgetLabel in the string.js file in Geoprocessing_autoexec\nls to be "Geoprocessing_autoexec"

4.  I modified the "uri" for the widget in the config.json folder to "widgets/Geoprocessing_autoexec/Widget".  (This was not a step you had mentioned but seemed like the right thing to do).

5.  I copied your code and pasted it over my startup: function() in the Widget.js of the Geoprocessing_autoexec widget

I haven't modified anything in the Widget.html file; should I have?

Thanks,


Brandon

0 Kudos
PrevinWong1
Esri Contributor

Brandon,

You should not have to do step 4.  Not sure if that causes any issues.  You should not have to modify the widget.html file as well.  I'll attached mine that I used.  See if it works for you.  Just drop it into client/stemapp/widgets and you should be good to go.

let me know if it works.

Thanks,

Previn

BrandonKeinath1
Deactivated User

I did as you suggested and put the customGP folder in client/sitemapp/widgets and I do see it when I open WAB.  However when I use the wizard to configure it spins after entering my gp service urlspinningwidget.JPG

I'm having trouble understanding, among other things, how the autoexecuting geoprocessing widget knows which widget folder to use if you don't tell it.  And my thinking was that you did specify it by changing the uri path in the config.json folder. 

Thanks,


Brandon

0 Kudos