In this topic
The Query widget allows you to retrieve information from source data by executing a predefined query. Data sources can be one of the following:
- Feature layer in the current map
- Feature layer as an item in the portal
- Feature layer from ArcGIS Server rest service
A feature layer can be from a map service or a feature service.
The Query widget serves as a query builder during configuration, allowing you to define the query by specifying source data, filter expression, and displaying fields in query results. Each query works with a single layer. However, you can define multiple queries for a single application and data layers can be from multiple sources.
Configuring the Query widget
The following steps indicate how to create a definition query. Repeat these steps if you need to define multiple queries.
- Hover the mouse over the Query widget and click the small edit icon
The configuration window for this widget opens.
- Optionally, click change widget icon if you want to replace the default icon for this widget.
A file explorer window opens allowing you to browse to a local image file to use as the widget icon.
- Click Add New next to Query Tasks.
The Set Data Source window opens. By default, Select from Map is chosen and all feature layers in the current map are listed below.
Alternatively, you can choose Select from Portal or Add Service URL.
- Choose the radio button next to a data source.
- Select a layer from the list.
- Click OK to close the Set Data Source window and return to the query configuration window.
By default, the Filter Definition tab is active.
- Click Add a filter expression to display the expression builder.
- Select a query field, an expression, and provide a value in the text box. Optionally, choose the Unique option to list all unique values for the selected field in the layer. This option is handy when your selected field is a string or number.
- Optionally, check Ask for values.
- You also have the option to use the Add an expression set, which allows you to define and apply two filters to a single query. Depending on if All or Any of the expressions in this set are true, either records meeting all the expressions or records meeting any of the expressions in the set return as the results.
- Click the Results Setting tab to activate it.
This tab allows you to configure the displayed title and contents for the query results. Fields from the data layer available for display show in this tab.
- Click Add Field next to the title text box.
The list of fields in the layer display and allows you to select one at a time. Values from the selected field display in the text box and are used as the query results title. Repeat this step to add additional fields. When multiple fields are added, the concatenation of field values are used as the result title.
- Check the fields you want to display in the results. For individual fields, the Special Type column allows them to display as a link or an image according to your selection. You can also click the up or down arrows in the Actions column to adjust the field order.
- Click the symbol for the query results.
The preview window opens, allowing you to choose the color and style for the result highlighting symbol.
- Click anywhere outside of the symbol preview window to close it.
- Click OK to close the Query window.
The query definition is saved and the query configuration window closes.
The filter expression can be a value based operation or an operation between two fields. Choosing the Unique option lists the unique values for the selected field in the layer. By default, Value is chosen.
When this option is chosen, provide both prompt texts and hint texts to save the query successfully; otherwise, an error message displays.
Using the Query widget
Clicking the Query widget in your application displays the list of predefined queries. Selecting a query displays the options for executing it:
- If Ask for values is specified at configuration time, a text box displays prompting you for a new value for the parameter. The default value shows in the box initially. If the unique values are set, the text box will list all of them for you to choose from.
- Use spatial filter—The spatial filter is applied on top of the query definition.
- Use current map extent—Only features falling within the current map extent and meeting the query definition return.
- Draw a graphic on the map—Only features falling within the graphic and meeting the query definition return.
- Add result as operational layer—When this option is checked, query results remain on the map until the Clear Results button is clicked.
You can select none or multiple options. Click Apply to execute the query and display the results. If the layer has related data, the related records are also included in the results. Features resulted from the query highlight on the map with the symbol specified at configuration time.