Access fields inside widget object?

4091
2
Jump to solution
02-11-2015 11:41 AM
AnthonyPreston1
New Contributor

This is probably best asked by stating an example.

The out-of-the-box Query widget contains a variable called tempResultLayer. I have another custom widget which would like to access this layer directly once it's been created by the query. I could go through map.getLayer(), but it seems there's no predictable layerId to reference it with, as the layerId appears to be generated on the fly with each query. The custom widget needs to collect an attribute value from each of the features returned by the query. (Alternatively, if there's a more straightforward way of accomplishing this without customizing the Query widget itself, I'm more than open to suggestions.)

So the question is - does the app builder support a means of accessing widget objects in this way, and getting at variables declared inside of them? I don't see any documentation this sort of access, or any other example of accessing app builder variables programmatically other than the this.map.id example in the tutorial.

0 Kudos
1 Solution

Accepted Solutions
JeremieCornet1
Occasional Contributor II

Hi Anthony,

All webapp builder widgets are dojo dijits.

Therefore, you can access a widget with dijit.byId(widget_id) :

var tmpLayer = dijit.byId("widget_id").tempResultLayer;

With this solution, you need to know the id of the out-of-the-box Query widget.

So you can use the widget manager (method getWidgetsByName) to get the search widget :

https://developers.arcgis.com/web-appbuilder/api-reference/widgetmanager.htm

Last but not least, you can use the communication system between widgets :

https://developers.arcgis.com/web-appbuilder/guide/communication-between-widgets.htm

In this case, you have to modify the query widget (add publishData when necessary).

View solution in original post

0 Kudos
2 Replies
JeremieCornet1
Occasional Contributor II

Hi Anthony,

All webapp builder widgets are dojo dijits.

Therefore, you can access a widget with dijit.byId(widget_id) :

var tmpLayer = dijit.byId("widget_id").tempResultLayer;

With this solution, you need to know the id of the out-of-the-box Query widget.

So you can use the widget manager (method getWidgetsByName) to get the search widget :

https://developers.arcgis.com/web-appbuilder/api-reference/widgetmanager.htm

Last but not least, you can use the communication system between widgets :

https://developers.arcgis.com/web-appbuilder/guide/communication-between-widgets.htm

In this case, you have to modify the query widget (add publishData when necessary).

0 Kudos
AnthonyPreston1
New Contributor

This pointed me in the right direction, thanks.

Once including the WidgetManager, the following worked to get at the Query widget:

wm = WidgetManager.getInstance();

q = wm.getWidgetsByName("Query");

Then, index [0] of "q" is the actual instance of the widget.

Also, it turns out, I needed to use .queryResults.resultLayer instead of tempResultsLayer, for anyone else who might be aiming to do something similar. The latter doesn't persist beyond the query operation itself, it appears.

0 Kudos