Configure a query widget

Queries provide a means of asking questions about the features in a data source and getting results that meet the criteria you specify. For example, a query for earthquakes might return which recent earthquakes were of a certain magnitude or greater, or a query for police incident reports can display the calls that have been received in the past 10 minutes.

Query widget criteria
This criterion queries for police incidents that were opened within the last 10 minutes.

To configure a query widget, you specify the data source and the query to perform, as well as a title and description. A query widget has a single data source, and all queries for the widget are based on that data source. If you want to define queries against different data sources, you need to create multiple query widgets. If you change the data source when there are existing queries defined for the widget, the existing queries are cleared.

The query can be either simple or parametric, which prompts the user for input. Simple queries use the same query expression each time they are executed. Simple queries are generally performed when a one-time question needs to be asked about a layer, or when the same query needs to be performed on a routine basis because the data associated with the query changes frequently. Parametric queries allow you to specify different criteria for one or more query parameters each time the query is executed. Parametric queries are generally used to allow user input that may vary with each use. You can combine a simple query with a parametric query. For example, you might want to limit demographic information to a particular state, but prompt for the age range, thus producing different results each time the query is executed.

Executing a query
The query for incidents in the last 10 minutes returned three resulting features. You can show or hide them on the map, zoom to them, or select them if selection has been enabled on the layer in the map. Reexecute runs the query again.

The results of the query can be displayed in a list widget. To do this, you need to add a list widget and set the query result as the data source.

Queries can be defined on any layer based on an ArcGIS map or feature service that has been published with a query service. You can find out if a layer has a query service by referring to the service details.

  1. Click Edit , and click Edit Operation View.
  2. To create a new widget, click Widget, click Add Widget, choose the type of widget, and click OK. To update settings for an existing widget, click Settings Settings, and click Configure Configure on the widget's window.
  3. Click the Data Source drop-down arrow, and choose the item that will provide the data for the widget.
  4. In the Title box, type a title that will be displayed in the widget's window.
  5. In the Description box, type a caption that will be displayed below the widget.
  6. Click Add to start building the query.
  7. In the Query Definition dialog box, type a name for the new query.
  8. Click the Query tab to specify the criteria.
  9. If your data contains subtypes, click the Type drop-down arrow and click the type you want to query against from the list.
    Type drop-down list
    • Select a particular type to query against features of that subtype. If you choose this option, all fields (other than the subtype field) are included in the Field drop-down list.
    • Select <All types> to query against all your subtypes. Based on your data, you will see different choices in the Field drop-down list. Fields with no domains are listed. Fields using a single coded domain or using range domains are listed. Fields using different coded domains or a mix of coded and range domains are not listed.
  10. Click the Field drop-down arrow and click the field you want to query against. The fields in the layer are listed by name, and the data type of the field is also shown. The data type affects what kind of operator and value you can apply in the query.
  11. Click the Operator drop-down arrow and choose the logical operator for the query from the list.
    • For string fields, you can choose Contains, Equal, Not equal, Is blank, or Is not blank.
    • For numeric fields, you can choose Equal, Greater than, Greater than or equal, Less than, Less than or equal, Not equal, Is blank, or Is not blank.
    • For date fields you can work absolute dates or dates relative to the current time. For absolute dates, you can choose Is on, Is not on, Is after, Is on or after, Is before, Is on or before, Is blank, or Is not blank. For relative dates, you can choose Is within, Is on or within, Is before, or Is on or before.
    • For fields with coded domains, you can choose Equal, Not equal, Is blank, or Is not blank.
  12. Build the query by specifying the field and operator. You can click the Data tab to see a subset of the features in the layer and their attributes. Seeing a sample of the values can help you build an appropriate query. If you change the properties of an existing query, you can also find out the name of the layer the query is performed against at the top of this tab.
    • If you want to query for a specific value, enter it in the Value box. If your field has a coded domain, choose a value from the drop-down list.
    • If you want the user to be prompted for a value, check the Prompt for value check box, and type the default value in the Value box. You should also include a Prompt and a Hint for the user when the query is executed; the prompt will be displayed as a message in an input dialog box, and the hint will be shown as a ScreenTip for the input.
    • If you are querying against the values in another field, click the Field tab, click the drop-down arrow, and click the field. You can choose a field when querying numeric and date fields.
    • You can perform queries on date fields to determine whether phenomena occurred on, before, or after a specific date, or within a range of dates. You can specify an absolute query, such as earthquakes that occurred after 3/4/2000 or fires that occurred before 1/1/2010, as well as a query relative to the current time when the query is executed. For example, you might set up a query for vehicles that have not reported status for the last two hours, earthquakes that have occurred in the last two months, or police incidents that have been assigned in the past 10 minutes.
  13. Click Add to add the criterion to the list.
  14. Optionally, build another query criterion and click Add. By default, the results of the query are those features that satisfy both criteria. You can choose instead to show features that satisfy either criterion by changing the logical operator button in the criteria list from And to Or. To group criteria in the query, select the criteria in the list, and click the Group button. You can also select a group of criteria, and click Ungroup to remove the grouping and apply the criteria separately in the order listed.
  15. Click OK when you are done setting the query criteria.
  16. You can add another query, as well as remove, edit, or reorder the queries in the widget.
  17. Click OK when you have built all the queries for the widget.