Use the Query element to query a data source, including sources such as ODBC, OLEDB, or LDAP.
The query can be run when the form is submitted or when a field changes.
Results of the query can be displayed in a repeating element if it contains more than one item.
-
Provide the Query with brackets around the connection column name when working with Solution Data Library or Reference Data connection types.
-
The Filter property of Query Control has been disabled for userfromgroup Data Connection.
Back to Form Elements
Related topic: Element Properties
Query Element Properties
|
Property |
Description |
|---|---|
|
Name |
A descriptive name for the element. |
|
Data Connection |
The name of the data connection. It can be, for example, SQL Server, ODBC, OLEDB, or LDAP. In case LDAP data connection is used, LDAP settings will be picked from Evolve server. |
|
Query |
Query to run on the data source. See help below. If a query is not provided, all data in the data connection is returned. |
|
Run at |
|
|
Field |
Runs the query when the specified field is changed. |
|
Set Fields |
Comma-separated list of query return values and fields to set in the form. The format is:
|
|
Append To Repeating Group |
Appends results to an existing repeating group. |
|
Ordinal |
The order (1, 2, and so on) in which the query should be performed when multiple Query elements are used. |
|
Clear Fields When Empty Return |
If the query returns no rows, selecting this option will cause the form fields to be cleared. This property works with Run At: On Field Change and Invoked by Rule only. |
|
Empty Message |
The message to display when the query returns no rows. If this field is left empty, no message is displayed. This property works with Run At: On Field Change and Invoked by Rule only. |
Add and Configure a Query
The following procedure shows you how to add and configure a query.
-
On the Elements tab, click Advanced Elements.
-
Click Query.
-
The Query element is inserted in the upper left corner of the form.
-
Click the Query button to open its properties in the Properties pane.
-
Under Data Connection, select the data connection for the query from the dropdown menu. (Note: You can click Add to add a data connection if necessary).
-
To add a query, under Query paste the query code into the query field.
Tip:If the Query is querying a SharePoint list, you only need the
filter=value because a Composer SharePoint data connection already has the SharePoint List name and the SharePoint List fields maintained in its properties.Example:
SharePointColumn==@[myFieldXPath], which can look like this in a real scenario:Code==@[/my:myFields/my:CurrencyCode] -
Sorting: When using query fields in Composer, the query is performed prior to Composer sorting fields. For instance, if your query only pulls back certain currencies, and the data connection is set to sort on Currency Rate, the data set will be sorted by currency rate only for the currencies the query field returns.
-
Under Run At, select when you want the Query to run:
-
Start: Run when the form is started
-
End: Run when the form is completed
-
When field changes: Run the Query when the field is changed
-
-
Below Set Fields, click Choose. Select the field(s) and the corresponding column(s) that will display the data returned by the Query.
-
Fill out the remaining information if needed. (See the properties table above for a description of each option.)
Configuring the Query element for SharePoint User Profile Services
The SharePoint User Profile Service needs the Login Name of the user before it can return anything. You can use the Current User element to obtain the login name for the currently logged in user and populate a field in your form with the Login Name.
Note: See Microsoft Technet article Default user profile properties table as a reference for when looking up SharePoint User Profile properties. Note that some properties appear to have spaces in them, but this is for display purposes only. The Query control requires the internal name of the property and not the display name to pass the value of the 'User Profile Property' column within the table.
SQL Query Examples
Some examples of Query being used for SQL queries are provided below.
Example 1
select top 1 Profession from [Job Title Taxonomy] where
ProfessionID =
[/my:myFields/my:PO13_Descriptions/my:PO13_Descriptions_Input/my:Search_Term]
This query returns just one row and one field, where a table column equals the value in a form field. Notice the square brackets around the table name (because it has spaces in it) and the full XPath of the form field name with square brackets.
top 1 in this example is SQL Server-specific; other databases may use
different syntax.
Example 2
select Profession from [Job Title Taxonomy] where
EmployeeName like
'[/my:myFields/my:PO13_Descriptions/my:PO13_Descriptions_Input/my:Search_Term]%'
Single quotes must be used around the XPath because the value returned is a string value with potential spaces. The percentage sign is used as a wildcard after the XPath value to ensure the return of all results starting with the value that comes from EmployeeName.
Single quotes are required around string values.
Example 3
select distinct ProfessionID from [Job Title Taxonomy]
This query returns unique values of ProfessionID from the
table. The results would then be mapped to a repeating section in a form,
which is then used as input for dropdown values. Because this can result in
very large tables, using SQL for this type of operation is faster and more
efficient.
Example 4
With a Solution Data Library and Reference Data, you have a select and a filter statement as shown in the query below.
Value from Form field:
[VendorName]=[/my:myFields/my:Vendor_Name]
This returns data where vendorname is equal to the value in the form field Vendor_Name.
Direct Value:
[VendorName]='Vendor1'
This returns data where vendorname is equal to Vendor1.
Example 5
If the value is numeric, single quotes around string values are not required.
[Country]=='[/my:myFields/my:Country]' AND [Region]=='[/my:myFields/my:Region]'