Is it possible to use a URL parameter with a Geoprocessing widget?

744
4
Jump to solution
03-01-2018 06:27 AM
LynnGaines
New Contributor III

Hi.  I would like to customize my URL to accommodate my geoprocessing widget parameter. Is this possible?  Thanks for your help.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Lynn,

   Inside your widgets code you can access the url parameters using ConfigManager.getInstance().urlParams

define([
...
'jimu/ConfigManager',
...
], function (
...
ConfigManager,
...

var cManager = ConfigManager.getInstance();
var urlParams = cManager.urlParams;

View solution in original post

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus

Lynn,

   Inside your widgets code you can access the url parameters using ConfigManager.getInstance().urlParams

define([
...
'jimu/ConfigManager',
...
], function (
...
ConfigManager,
...

var cManager = ConfigManager.getInstance();
var urlParams = cManager.urlParams;
0 Kudos
LeonAus
New Contributor III

Hi Robert,

Thanks for this snippet, exactly what I need, and all your posts really, they have helped me out greatly.

The question I have, which to this point has confused me, is if I run this code in it's own widget with nothing else, it works fine, but when I first copied this code into an existing widget (a search widget for example) in an already existing app, I was unable to get an instance of the ConfigManager with an error saying TypeError: ConfigManager.getInstance is not a function.

After playing around I was able to get an instance, and I think what did the trick was moving the 'jimu/ConfigManager' and ConfigManager (lines 3 & 7 in your example), directly after the 'jimu/BaseWidget' and BaseWidget lines, but I also deployed the widget with nothing else that worked to the app through the web appbuilder GUI, and restarted web appbuilder after.

I've had this problem trying to add references to my app before and I have been able to get them to work with a combination of creating examples through the demo widget process, saving them to the stemapps folder, deploying the example widget to the app, testing the example widget, restarting web appbuilder, then the code in the existing widget will be able to get an instance.

Right now I feel like an superstitious sports player that has to touch his belt 3 times, adjust hat, tap all 4 corners of the home plate in the same order, then it will work. Wondering if you can enlighten me?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Leon,

   So your likely issue is that when you define modules their associated parameters in the function have to be in the same order you define the modules inside the array. For example:

define([
...
'dojo/_base/lang',
'jimu/ConfigManager',
'esri/Color',
...
], function (
...
lang,
ConfigManager,
Color
...

Notice dojo lang is listed then ConfigManager, then Color. Now in the function parameters have to be listed in that same Exact order as above. So in this next example I will show and explain improper ordering and the result.

define([
...
'dojo/_base/lang',
'jimu/ConfigManager',
'esri/Color',
...
], function (
...
ConfigManager,
Color,
lang,
...‍‍‍‍‍‍‍‍‍‍‍‍

Now in the above code the parameter ConfigManager is associated/linked to the dojo lang module and it does not have a getInstance function, and the Color parameter is linked to the jimu Configmanager, etc, etc.

LeonAus
New Contributor III

:facepalm:

Right you are Robert. Thanks again.

0 Kudos