Queries#
Administration.Queries
Overview#
The Queries page provides access to the maintenance of queries. A Query is an inquiry to the system for a given entity type to return the records that match specific criteria. Queries can also be used as Widgets for Dashboards.
Browsing Queries#
Selecting the Queries page will display the Queries folder structure. Selecting a folder will show its contents in the table on the right.
The folder structure on the left side allows you to:
- Create New Folder
- Edit a Folder
- Delete a Folder
Create, Edit, and Delete Folders
Available actions depend on the folder selected in the folder tree. Depending on your current location, some options may be unavailable. Moreover, a folder can only be deleted when it is empty.
Info
Private queries are displayed in the list with a distinctive marker. They are visible only to the user who created the query or to users in the Administrators special group. Editing the query or changing its visibility to public is restricted to the creator and members of the Administrators group. Similarly, only the creator can change the visibility of a query from public to private.
To view the details of a specific Query, simply select its name to display information similar to the example below. Each Query includes an information button that provides the ID, the creation date and creator, as well as the last modification date and the person who made the changes.
Creating a Query#
Query.Create
Query.ManagePrivate
To create a new Query, select the Create button on the top ribbon and then follow the steps below.
Step 1: Details
- Enter the name and, optionally, a description. Note that the Query name must be unique within the folder.
- Select the folder where the query should be created.
- Select the entity type for the query.
- Select whether this will be the default query for the chosen entity type.
- Select the maximum number of results.
- Select whether the distinct attribute is enabled or not. If enabled, the results will not contain duplicated values.
- Select whether this will be a public or private query.
- Optionally, enter a Comment.
- Select Create to complete the operation.
Using a Query#
After the creation of a new Query or when opening an existing one, the Query page is opened. This page is mainly divided into two sections:
- Filters - containing the search properties for the query.
- Results - showing the results returned by the query.
Build a Query with AI#
AI.AskAI
Query.Edit
When AI is configured, use the AI Editor to build or refine a saved, non-system Query with natural-language instructions. Open the Query and select AI Editor. The CM Query Builder Agent can help configure columns, filters, and paths to related entities, then test its changes before saving them.
The example below shows the agent adding a Description column and the updated query results.
The AI Editor works on the Query currently open in the editor and does not change its root entity type. To query a different entity type, open a Query for that type first. For more information, see Available AI Agents.
In order to select the filters to apply to the Query, follow the steps below:
- Expand the Filters section.
- Select the Add Filter button. This will open the Search Entity Property window.
- In the Search Entity Property, choose the desired property, and select Confirm.
After adding the desired properties to the filter section, you can:
- Choose the logical operator to connect the expressions
-
Choose the filter type to apply. The currently supported filters are:
- Is equal to - finds records with an exact match.
- Is not equal to - returns records that do not exactly match.
- Greater than - finds records where the value is greater than the specified value.
- Greater than or equal to - finds records where the value is greater than or equal to the specified value.
- Lesser than - finds records where the value is less than the specified value.
- Lesser than or equal to - finds records where the value is less than or equal to the specified value.
- Like - finds records matching the search string that can use wildcards (
%for any sequence or characters and_for a single character). - Not like - finds records not matching the search string that can use wildcards (
%for any sequence or characters and_for a single character). - Contains - finds records that contain a certain string.
- Starts with - finds records that start with a certain string.
- In (only for objects) - finds records that are included in a set of user defined objects.
- Not in (only for objects) - finds records that are not included in a set of user defined objects.
Info
String comparisons are case-insensitive.
-
Choose to use parameters, by activating the Parameter property. By choosing to use parameters, it also possible to mark it as Optional. For more information, see Query Parameters.
It is possible to use special dynamic tokens in the queries, such as:
- @Today, which represents the current date.
- @Now, which represents the current date and time.
For the case of Today and Now it is possible to add and subtract times using a simple '+' or '-' arithmetic:
- @Today +1d represents the current date plus one day.
- @Today -1M represents the current date minus one month.
- @Today -1y represents the current date minus one year.
- @Now -1m represents the current date and time minus one minute.
- @Now +10s represents the current date and time plus ten seconds.
There are also special tokens available for certain property types:
- @Employee, which represents the current Employee.
- @User, which represents the current User.
- @UserRoles, which represents all the Roles of the current User (can only be used in properties of type Role).
Having done this, it is possible to execute the Query by selecting the Execute Button.
Info
After saving, the Query becomes available in the Business Data for the entity Type it applies and on the specified path. The different Queries appear under the Query Selection.
In the results section, it is also possible to choose which columns to show, by selecting the Column Options button. These options may include entity operation attributes if the Query.AdvancedMode security feature is enabled. In this section, it is possible to choose which properties are to be included in the output table, as well as their sort order, how they are to be presented in the Setup Tab, and the different type of joins available in the Joins Tab. These are:
- Inner Join - display only records which exist both on the source and target tables.
- Outer Join - display all records which exist at least in the source or the target.
- Right Join - display all records which exist on the target (right-side) even if they don't exist in the source.
- Left Join - display all records which exist on the source (left-side) even if they don't exist in the target.
Note
When you select a column that is a relation to another object (for example, LastProcessedResourceName in Material is related to Resource), the GUI will let you select what columns you would like to see from the destination object.
Relation Filters and Join Direction#
A relation has a source entity and a target entity. The entity selected for the Query can be either endpoint. Check the relation direction in Column Options before selecting a join: Right Join preserves records on the target side, and Left Join preserves records on the source side. The query entity is not always the source of the relation.
Find Materials Without a Protocol#
For a Query on Material, the ProtocolMaterial relation has the Material as its target and the Protocol Instance as its source. To find Materials without an associated Protocol Instance:
- Add a filter on
ProtocolMaterial > SourceEntitywith the Is Null operator. - Open Column Options and go to the Joins section.
- Set the join for
ProtocolMaterialto Right Join, and leave the join forSourceEntityas Inner Join. - Apply the column options and execute the Query.
The Right Join preserves the Materials that have no matching relation. The Is Null filter selects those unmatched Materials. An Outer Join also includes unmatched records from both sides; use it only when that is the result you need.
To filter by a Protocol Instance instead, use Is Equal To on ProtocolMaterial > SourceEntity and mark its value as an optional parameter. Selecting an instance limits the results to Materials associated with that instance. Leaving the parameter empty omits that filter; other filters still apply. For more information, see Query Parameters.
Upgrade Compatibility#
Review Custom Queries After Upgrading
From versions 10.2.18, 11.3.7, and 12.0.1, and also in version 12.1, relation joins preserve their Left Join and Right Join meaning when the query entity is the target of a relation. Custom queries that used Right Join where Left Join was intended to compensate for the earlier behavior can return different results after upgrading.
Review the direction of each relation and the records that the query must preserve before changing its join. Execute the query with and without optional parameter values after the upgrade. Do not replace all Right Joins automatically.
Query Parameters#
It is possible to use parameters in a Query. In order to that, you need to flag the filter value as a parameter. When trying to execute a Query with parameters, the system will prompt you for the parameter values. If the parameter is marked as optional, you can choose to ignore it, in which case the filter expression is removed from the query execution.
Query Filters#
A Query can contain one or more filters to restrict the data that is selected. The system also supports nested filter groups. Each filter (or filter group) needs to be connected with an AND or OR logical operator.
Generating Query Code#
It is possible to generate the query code in C#, TypeScript, or JSON. The C# and TypeScript output translates the query into code that can be used to programmatically implement the query in client code. In the generated-code view, select the JSON tab to view the query definition. You can copy it or export it as a .json file. Use this JSON as an inline Query Schema in a UI Page's Query Data Source or Query Widget.
Note
May also be useful to look at the Open Data Protocol (OData) tutorial.










