Last updated: 2024-06-07
Conditions
In this topic:
Overview
Conditions are defined in the XML format, and the structure of the XML is similar to SQL queries. Conditions are used in search and sync operations.
XML Structure
Here is an an example of a condition that specifies the object property to be evaluated (Contact.Name), the operation to be used for evaluating the property (like), and the value for the condition (A%):
<condition>
<expr prop="Contact.Name" op="like">
<v>A%</v>
</expr>
</condition>Note the following:
- A
conditionelement contains a condition definition. Conditions can be nested, i.e., one condition can contain another condition. - The
exprelement defines a minimal Boolean expression. - The
andandorelements (not shown in the example) can be used with expressions and conditions to represent Boolean operators.
Expression
The expr element defines a minimal Boolean expression. The left side of the expression is a property, while the right side can have one or more constant values or a property. The left-side information is defined by the following expr element attributes:
| Attribute | Description | Examples |
|---|---|---|
prop | Left-side property name in the format object.property.sub-property. | Contact.TypeContact.PreferredPhone.AreaCode |
op | The operator that you want to use for the expression. See Operators. | |
fn | An optional function that can be applied to the specified property to further refine the search. See Functions. |
Value
Once you define the expr element and its attributes, use the v element to define the value or values for the right side of the expression.
Note: When an expression uses the isnull or not-null operator, do not include a v element.
The v element can have the following attributes:
| Attribute | Description | Notes |
|---|---|---|
type | The value type. Acceptable types are: • prop : property name• const : constant value• ref : reference to current object's property value | When no type attribute is set, SmartIntegrator assumes that the type is const.The const type must be used when the expression uses any of these operators: between, in, like, starts, ends, contain.The ref type is for referring objects/properties. |
fn | See Functions. |
Operators
The following table summarizes the operators that can be used as attributes for the expr element.
| Operator | Description | Examples |
|---|---|---|
eq | Equal to | |
gt | Greater than | |
ge | Greater than or equal to | |
lt | Less than | |
le | Less than or equal to | |
ne | Not equal to | |
between | Between two values (must be integers) | Find contacts whose Type is a value between 1 and 10:<expr prop="Contact.Type" op="between"><v>1</v><v>10</v></expr> |
like | Matching a specified pattern. Accepts the wildcards % (for no, one or multiple characters) and _ (for only one character) in the v element. Note that your application is responsible for escaping special characters in the string value. | Find contacts whose name starts with "A" followed by no, one or multiple characters:<expr prop="Contact.Name" op="like"><v>A%</v></expr> |
contains | Contains a text string | Find contacts whose name contains the characters "abc" (in SQL syntax, this would be name like '%abc%'):<expr prop="Contact.Name" op="contains"><v>abc</v></expr> |
starts | Starts with a text string | Find contacts whose name begins with the letter "A" (in SQL syntax, this would be name like 'A%'):<expr prop="Contact.Name" op="starts"><v>A</v></expr> |
ends | Ends with a text string | Find contacts whose name ends with the letter "A" (in SQL syntax, this would be name like '%A'):<expr prop="Contact.Name" op="ends"><v>A</v></expr> |
in | Test if a property is from a list of values. Only simple type values are allowed. | Find contacts who Type is 1, 2 or 3 (in SQL syntax, this would be type in (1,2,3)’):<expr prop="Contact.Type" op="in"><v>1</v><v>2</v><v>3</v></expr> |
isnull | Is null. Note that this operator takes no v element. | Find contacts with no first name (in SQL syntax, this would be name is null):<expr prop="Contact.FirstName" op="isnull" /> |
not-between | Not between | |
not-in | Not in | |
not-null | Is not null. Note that this operator takes no v element. | |
not-like | Not like | |
not-contains | Not contains | |
not-starts | Not starts | |
not-ends | Not ends | |
any | Any of the child object matches with the given data (supported only by the sync operation’s logic_step condition.) |
Functions
To refine a query, you can apply a function to a property by adding the fn attribute to the expr element. The following example uses the MONTH function to find contacts with a date of birth in March:
<expr prop="Contact.Dob" op="eq" fn="MONTH">
<v>3</v>
</expr>SmartIntegrator supports only those SQL functions that are supported by the SmartOffice framework. The queried object must support the function in order for SmartIntegrator to return a result. Functions can only be applied to properties.
The available functions are:
YEARMONTHDAY(Day of montth, i.e., 1–31)HOURMINUTESECONDQUARTER(Quarter of year)WEEKOFYEAR(Week of year)DAYOFYEARDAYOFWEEKUCASE(Upper case)LCASE(Lower case)
Child Object Properties
Searchable properties of child objects can also be specified in an expression. Relationships must be defined by the sub-type and foreign keys.
This sample expression looks for all contacts with a postal code of 91106.
<expr prop="Contact.PreferredAddress.Postal" op="eq">
<v>91106</v>
</expr>Sort
The sort element defines the object property by which data returned by SmartIntegrator will be sorted. Only searchable properties can be sorted.
Within the sort element, use the item element with the following attributes to specify the sorting:
| Attribute | Description |
|---|---|
prop | The name of a property. This is a short name and does not include an object name. |
order | Accepts one of two values: asc (ascending) or desc (descending). The default is asc. |
Example:
<sort>
<item prop="AreaCode" order="asc"/>
</sort>Sorting is supported up to two levels of properties. For example:
<sort>
<item prop="Assignment.Contact" order="asc"/>
</sort>