Calling a Widget/Service from Another Widget

861
3
07-24-2018 08:59 AM
CraigPrisland2
New Contributor III

Hello all,

I have been looking through the communication between widgets post from above but haven't been able to successfully accomplish what I am working on.  What I am trying to accomplish is the following: 

I have a geoprocessing service that I am using in a geoprocessing widget which concatenates several address fields (i.e. house number, street pre dir, street name, etc..) into one full address field.  I also have a custom "Reporting" widget which uses this full address field (as well as others) and creates a PDF.  Currently my workflow consists of the user having to first run the geoprocessing widget (there are no user inputs in this widget so I added the "this._onExecuteClick():" syntax to auto-execute when the user clicks on the widget) and then have to run the Reporting widget.  What I am trying to accomplish is not having the user to first click on the geoprocessing widget and have syntax in the Reporting widget where it would first call and run the geoprocessing service prior to running the Reporting widget.  Any assistance would be greatly appreciated.

 

I am using the Tab Theme in WAB Dev 2.6

 

Thanks,

Craig

0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Craig,

   Here is a thread where I show someone how to open the print widget from another widget.

https://community.esri.com/thread/180567#comment-624664 

You can use this code as a basis of what you are after. Once you have a reference to the widget you are interested in then can call any of the functions inside that widget using the widget object and the function name.

0 Kudos
CraigPrisland2
New Contributor III

Robert,

 

Thank you for the reference.  The past few days I have been trying to get this to work correctly but am running into some issues.  The following is my current code:

 

define(['dojo/_base/declare', 'jimu/BaseWidget', 'dijit/_WidgetsInTemplateMixin', 'dojo/i18n!./nls/strings', 'dijit/form/Select', 'dojo/Deferred', 'jimu/dijit/Message', './GenerateReports', 'esri/tasks/query', 'esri/layers/FeatureLayer', 'esri/graphicsUtils', 'esri/symbols/SimpleMarkerSymbol', 'esri/tasks/PrintTask', 'esri/tasks/PrintParameters', 'esri/tasks/PrintTemplate', 'jimu/dijit/DrawBox', 'dojo/on', 'dojo/_base/lang', 'dojo/dom-class', 'dojo/_base/array', 'dojo/dom-construct', 'dijit/form/Form', 'dijit/form/Select', 'dijit/form/NumberTextBox', 'dijit/form/Button', 'dijit/form/CheckBox', 'dijit/ProgressBar', 'dijit/form/DropDownButton', 'dijit/TooltipDialog', 'dijit/form/RadioButton', 'dijit/form/SimpleTextarea', 'dijit/form/DateTextBox', 'dijit/form/Textarea', 'jimu/dijit/CheckBox', 'jimu/WidgetManager', 'jimu/PanelManager'], function (declare, BaseWidget, _WidgetsInTemplateMixin, i18n, Select, Deferred, Message, GenerateReports, Query, FeatureLayer, graphicsUntils, SimpleMarkerSymbol, PrintTask, PrintParameters, PrintTemplate, DrawBox, on, lang, domClass, array, domConstruct, WidgetManager, PanelManager) {
  return declare([BaseWidget, _WidgetsInTemplateMixin], {
      
    _getWidgetConfig: function(Geoprocessing){  
      var widgetCnfg = null;  
      array.some(WidgetManager.getInstance().appConfig.widgetPool.widgets, function(Geoprocessing){
          widgetCnfg = aWidget;  
          return true;  
        }  
        return false;  
      });
      if(!widgetCnfg){  
        /*Check OnScreen widgets if not found in widgetPool*/  
        array.some(WidgetManager.getInstance().appConfig.widgetOnScreen.widgets, function(Geoprocessing) {  
          if(aWidget.name == Geoprocessing) {  
            widgetCnfg = aWidget;  
            return true;  
          }  
          return false;  
        });  
      }  
      return widgetCnfg;  
    },
      
    _openGeoprocessingWidget: function() {  
         var GeoprocessingWidget, sbc;  
         var widgetCfg = this._getWidgetConfig('Geoprocessing');  
         if (widgetCfg) {  
             sbc = WidgetManager.getInstance().getWidgetsByName("SidebarController")[widgets_Geoprocessing_Widget_46];  
             sbc._resizeToMax();  
             sbc.setOpenedIds([widgetCfg.id]);
        }
    }
        
    this._openGeoprocessingWidget();       

 

When reviewing the errors in the Dev Tools I am getting the following errors:

 

Any assistance would be greatly appreciated!

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Craig,

  So those errors mean you have a syntax error in your code changes. Do you have more functions after the _openGreoProcessingWidget? if so then you need a comma after that function. Also you have issues in your AMD modules array.

define([
  'dojo/_base/declare', 'jimu/BaseWidget', 'dijit/_WidgetsInTemplateMixin', 'dojo/i18n!./nls/strings', 'dijit/form/Select', 'dojo/Deferred', 'jimu/dijit/Message', './GenerateReports', 'esri/tasks/query', 'esri/layers/FeatureLayer', 'esri/graphicsUtils', 'esri/symbols/SimpleMarkerSymbol', 'esri/tasks/PrintTask', 'esri/tasks/PrintParameters', 'esri/tasks/PrintTemplate', 'jimu/dijit/DrawBox', 'dojo/on', 'dojo/_base/lang', 'dojo/dom-class', 'dojo/_base/array', 'dojo/dom-construct',
'jimu/WidgetManager', 'jimu/PanelManager', 'dijit/form/Form', 'dijit/form/Select', 'dijit/form/NumberTextBox', 'dijit/form/Button', 'dijit/form/CheckBox', 'dijit/ProgressBar', 'dijit/form/DropDownButton', 'dijit/TooltipDialog', 'dijit/form/RadioButton', 'dijit/form/SimpleTextarea', 'dijit/form/DateTextBox', 'dijit/form/Textarea', 'jimu/dijit/CheckBox'
],
function (
  declare, BaseWidget, _WidgetsInTemplateMixin, i18n, Select, Deferred, Message, GenerateReports, Query, FeatureLayer, graphicsUntils, SimpleMarkerSymbol, PrintTask, PrintParameters, PrintTemplate, DrawBox, on, lang, domClass, array, domConstruct, WidgetManager, PanelManager
) {
  return declare([BaseWidget, _WidgetsInTemplateMixin], {‍‍‍

Notice above I put WidgetManager and PanelManager after dom-construct, this way is aligns with your variable declarations proceeding the module array.

0 Kudos