Advanced SmartObjects: Query method

A query method is a SmartObject method that runs a SQL SELECT query and returns the results as a list. Use a query method when a view, form, or control needs a summary or a subset of SmartObject data, instead of every record. For example, a query method can return the number of open requests for a metric tile. It can also return a total for each category for a chart or the distinct values for a drop-down list.

You add query methods to an advanced SmartObject on the Methods tab. Each query reads data from one SmartObject, which you name in the query's FROM clause. This can be the SmartObject you add the method to, or a different SmartObject. For example, you can create an advanced SmartObject named Ticket Reports that holds only query methods, and have each method read from a Ticket SmartObject.

The query runs on the server, so the data is filtered, grouped, and sorted before it reaches the view or form at runtime. The columns the query returns become properties of the SmartObject that holds the method. Each has a data type, so you can use them like any other SmartObject property.


Before you begin

  • The query method is saved on an advanced SmartObject. You can create a new advanced SmartObject or change an existing SmartBox SmartObject to an advanced SmartObject. If you change a SmartBox SmartObject, save it first. See Advanced SmartObjects.
  • The SmartObject the query reads from must have at least one List method. It can be any SmartObject, whatever its data source.
  • You can't change an existing method into a query method. Instead, create a query method that reads from the existing List method, for example FROM [Ticket].[GetList]. The existing method doesn't change, so the views, forms and workflows that use it aren't affected.
  • The query can use only the properties that the List method returns. You can't select or filter on a property that the List method doesn't return. To give a value to one of the List method's input properties or parameters, use HAVING. See Write a query.
  • Use system names in the query, not display names. A system name is the display name with each space replaced by an underscore. For example, a SmartObject named Ticket Reports is [Ticket_Reports], and a property named Logged By is [Logged_By]. To check a SmartObject's system name, select it in the category tree in the Designer: the System Name shows in its details.

See the following resources for more information: